Zepp OS: Fix invalid files being recognized as maps

This commit is contained in:
José Rebelo
2025-04-02 20:26:00 +01:00
parent e9bb18b811
commit 0abd54af98
3 changed files with 18 additions and 3 deletions
@@ -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;
@@ -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;
@@ -96,7 +96,7 @@ public class ZeppOsMapsFile {
return false;
}
return true;
return uncompressedSize > 0;
}
public Uri getUri() {