Fail early when opening a pebble file.

Fixes #102

We could also use a whitelist approach instead, but we can't be sure that the user installs a file with .fw extension, hence i preferred to only avoid loading files which are known to be of the wrong type.
live-activity-data
Daniele Gobbetti 2015-08-31 17:40:46 +02:00
parent 9360b81ef3
commit ee3ca5998e
1 changed files with 6 additions and 0 deletions

View File

@ -38,6 +38,12 @@ public class MiBandFWHelper {
this.uri = uri;
cr = context.getContentResolver();
String pebblePattern = ".*\\.(pbw|pbz)";
if (uri.getPath().matches(pebblePattern)) {
throw new IOException("Firmware has a filename that looks like a Pebble app/firmware.");
}
try (InputStream in = new BufferedInputStream(cr.openInputStream(uri))){
this.fw = FileUtils.readAll(in, 1024 * 1024); // 1 MB
if (fw.length <= firmwareVersionMajor || fw[firmwareVersionMajor] != 1) {