mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Zepp OS: Fix invalid files being recognized as maps
This commit is contained in:
+8
-1
@@ -42,6 +42,8 @@ public class ZeppOsAgpsInstallHandler implements InstallHandler {
|
||||
protected final Context mContext;
|
||||
private ZeppOsAgpsFile file;
|
||||
|
||||
private static final int MAX_EXPECTED_SIZE = 1024 * 1024; // 1MB, they're usually ~128KB
|
||||
|
||||
public ZeppOsAgpsInstallHandler(final Uri uri, final Context context) {
|
||||
this.mContext = context;
|
||||
|
||||
@@ -53,8 +55,13 @@ public class ZeppOsAgpsInstallHandler implements InstallHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
if (uriHelper.getFileSize() > MAX_EXPECTED_SIZE) {
|
||||
LOG.debug("Not agps - file too large");
|
||||
return;
|
||||
}
|
||||
|
||||
try (InputStream in = new BufferedInputStream(uriHelper.openInputStream())) {
|
||||
final byte[] rawBytes = FileUtils.readAll(in, 1024 * 1024); // 1MB, they're usually ~128KB
|
||||
final byte[] rawBytes = FileUtils.readAll(in, MAX_EXPECTED_SIZE);
|
||||
final ZeppOsAgpsFile agpsFile = new ZeppOsAgpsFile(rawBytes);
|
||||
if (agpsFile.isValid()) {
|
||||
this.file = agpsFile;
|
||||
|
||||
+9
-1
@@ -39,6 +39,8 @@ import nodomain.freeyourgadget.gadgetbridge.util.UriHelper;
|
||||
public class ZeppOsGpxRouteInstallHandler implements InstallHandler {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ZeppOsGpxRouteInstallHandler.class);
|
||||
|
||||
private static final int MAX_EXPECTED_SIZE = 1024 * 1024; // 1MB, they're usually ~128KB
|
||||
|
||||
protected final Context mContext;
|
||||
private ZeppOsGpxRouteFile file;
|
||||
|
||||
@@ -52,8 +54,14 @@ public class ZeppOsGpxRouteInstallHandler implements InstallHandler {
|
||||
LOG.error("Failed to get uri", e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (uriHelper.getFileSize() > MAX_EXPECTED_SIZE) {
|
||||
LOG.debug("Not gpx - file too large");
|
||||
return;
|
||||
}
|
||||
|
||||
try (InputStream in = new BufferedInputStream(uriHelper.openInputStream())) {
|
||||
final byte[] rawBytes = FileUtils.readAll(in, 1024 * 1024); // 1MB
|
||||
final byte[] rawBytes = FileUtils.readAll(in, MAX_EXPECTED_SIZE);
|
||||
final ZeppOsGpxRouteFile gpxFile = new ZeppOsGpxRouteFile(rawBytes);
|
||||
if (gpxFile.isValid()) {
|
||||
this.file = gpxFile;
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ public class ZeppOsMapsFile {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return uncompressedSize > 0;
|
||||
}
|
||||
|
||||
public Uri getUri() {
|
||||
|
||||
Reference in New Issue
Block a user