Bug 1174922 - NativeZip does not null-terminate zip entry comparisons correctly, r=nchen

This commit is contained in:
Mark Capella 2015-07-29 01:03:26 -04:00
parent 34851cda19
commit 48fba8ca8a
3 changed files with 14 additions and 4 deletions

View File

@ -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");

View File

@ -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");

View File

@ -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: