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.
This commit is contained in:
parent
9360b81ef3
commit
ee3ca5998e
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue