From 48fba8ca8a22bf7084ad758ea6d35bd5e947fc15 Mon Sep 17 00:00:00 2001 From: Mark Capella Date: Wed, 29 Jul 2015 01:03:26 -0400 Subject: [PATCH] Bug 1174922 - NativeZip does not null-terminate zip entry comparisons correctly, r=nchen --- .../mozilla/tests/browser/junit3/TestJarReader.java | 6 ++++++ .../android/tests/browser/robocop/testJarReader.java | 10 +++++++--- mozglue/linker/Zip.h | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/mobile/android/tests/browser/junit3/src/org/mozilla/tests/browser/junit3/TestJarReader.java b/mobile/android/tests/browser/junit3/src/org/mozilla/tests/browser/junit3/TestJarReader.java index a995edcdac4..70a8afe1aae 100644 --- a/mobile/android/tests/browser/junit3/src/org/mozilla/tests/browser/junit3/TestJarReader.java +++ b/mobile/android/tests/browser/junit3/src/org/mozilla/tests/browser/junit3/TestJarReader.java @@ -40,6 +40,12 @@ public class TestJarReader extends InstrumentationTestCase { stream = GeckoJarReader.getStream(context, "jar:" + url + "!/chrome/chrome/content/branding/favicon32.png"); assertNull(stream); + // Test looking for a file that doesn't exist in the APK. + // Bug 1174922, prefixed string / length error. + url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME + "BAD"; + stream = GeckoJarReader.getStream(context, "jar:" + url + "!/chrome/chrome/content/branding/favicon32.png"); + assertNull(stream); + // Test looking for an jar with an invalid url. url = "jar:file://" + appPath + "!" + "!/" + AppConstants.OMNIJAR_NAME; stream = GeckoJarReader.getStream(context, "jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png"); diff --git a/mobile/android/tests/browser/robocop/testJarReader.java b/mobile/android/tests/browser/robocop/testJarReader.java index 81109ef14c8..9310599d364 100644 --- a/mobile/android/tests/browser/robocop/testJarReader.java +++ b/mobile/android/tests/browser/robocop/testJarReader.java @@ -16,14 +16,12 @@ import android.content.Context; * as loading some invalid jar urls. */ public class testJarReader extends BaseTest { - public void testGetJarURL() { + public void testJarReader() { // Invalid characters are escaped. final String s = GeckoJarReader.computeJarURI("some[1].apk", "something/else"); mAsserter.ok(!s.contains("["), "Illegal characters are escaped away.", null); mAsserter.ok(!s.toLowerCase().contains("%2f"), "Path characters aren't escaped.", null); - } - public void testJarReader() { final Context context = getInstrumentation().getTargetContext().getApplicationContext(); String appPath = getActivity().getApplication().getPackageResourcePath(); mAsserter.isnot(appPath, null, "getPackageResourcePath is non-null"); @@ -43,6 +41,12 @@ public class testJarReader extends BaseTest { stream = GeckoJarReader.getStream(context, "jar:" + url + "!/chrome/chrome/content/branding/favicon32.png"); mAsserter.is(stream, null, "JarReader returned null for valid file in invalid jar file"); + // Test looking for a file that doesn't exist in the APK. + // Bug 1174922, prefixed string / length error. + url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME + "BAD"; + stream = GeckoJarReader.getStream(context, "jar:" + url + "!/chrome/chrome/content/branding/favicon32.png"); + mAsserter.is(stream, null, "JarReader returned null for valid file in other invalid jar file"); + // Test looking for an jar with an invalid url. url = "jar:file://" + appPath + "!" + "!/" + AppConstants.OMNIJAR_NAME; stream = GeckoJarReader.getStream(context, "jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png"); diff --git a/mozglue/linker/Zip.h b/mozglue/linker/Zip.h index 76256a14c24..2f1b5c3a221 100644 --- a/mozglue/linker/Zip.h +++ b/mozglue/linker/Zip.h @@ -270,7 +270,7 @@ private: */ bool Equals(const char *str) const { - return strncmp(str, buf, length) == 0; + return (strncmp(str, buf, length) == 0 && str[length] == '\0'); } private: