Bug 1328865 - Make nsJARURI::SetSpecWithBase ignore URL fragments. r=valentin
authorDaniel Stenberg <daniel@haxx.se>
Sun, 18 Jun 2017 23:52:00 -0400
changeset 364703 8cbeddfc615e7ab54c6f42117bb02071b8443c9b
parent 364702 8da651d21bb56dad086f53fe01b444883df1bd1e
child 364704 dceb915d3c4008af14d691a622216d2986104033
push id32053
push userkwierso@gmail.com
push dateTue, 20 Jun 2017 00:30:11 +0000
treeherdermozilla-central@416c3c8c4b3d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1328865
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1328865 - Make nsJARURI::SetSpecWithBase ignore URL fragments. r=valentin As otherwise it could wrongly find !/ delimiters with that.
modules/libjar/nsJARURI.cpp
modules/libjar/test/unit/test_bug1328865.js
modules/libjar/test/unit/xpcshell.ini
--- a/modules/libjar/nsJARURI.cpp
+++ b/modules/libjar/nsJARURI.cpp
@@ -283,16 +283,25 @@ nsJARURI::SetSpecWithBase(const nsACStri
     aSpec.BeginReading(begin);
     aSpec.EndReading(end);
 
     while (begin != end && *begin != ':')
         ++begin;
 
     ++begin; // now we're past the "jar:"
 
+    nsACString::const_iterator frag = begin;
+    while (frag != end && *frag != '#') {
+        ++frag;
+    }
+    if (frag != end) {
+        // there was a fragment, mark that as the end of the URL to scan
+        end = frag;
+    }
+
     // Search backward from the end for the "!/" delimiter. Remember, jar URLs
     // can nest, e.g.:
     //    jar:jar:http://www.foo.com/bar.jar!/a.jar!/b.html
     // This gets the b.html document from out of the a.jar file, that's 
     // contained within the bar.jar file.
     // Also, the outermost "inner" URI may be a relative URI:
     //   jar:../relative.jar!/a.html
 
@@ -307,16 +316,17 @@ nsJARURI::SetSpecWithBase(const nsACStri
     if (NS_FAILED(rv)) return rv;
 
     NS_TryToSetImmutable(mJARFile);
 
     // skip over any extra '/' chars
     while (*delim_end == '/')
         ++delim_end;
 
+    aSpec.EndReading(end); // set to the original 'end'
     return SetJAREntry(Substring(delim_end, end));
 }
 
 NS_IMETHODIMP
 nsJARURI::GetPrePath(nsACString &prePath)
 {
     prePath = NS_JAR_SCHEME;
     return NS_OK;
new file mode 100644
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug1328865.js
@@ -0,0 +1,24 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+Cu.import("resource://gre/modules/NetUtil.jsm");
+
+// Check that reading non existant inner jars results in the right error
+
+function run_test() {
+  var file = do_get_file("data/test_bug597702.zip");
+  var ios = Cc["@mozilla.org/network/io-service;1"].
+            getService(Ci.nsIIOService);
+  var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
+  var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello#!/ignore%20this%20part";
+  var goodChannel = NetUtil.newChannel({uri: goodSpec, loadUsingSystemPrincipal: true});
+  var instr = goodChannel.open2();
+
+  ok(!!instr, "Should be able to open channel");
+}
--- a/modules/libjar/test/unit/xpcshell.ini
+++ b/modules/libjar/test/unit/xpcshell.ini
@@ -36,8 +36,9 @@ skip-if = os == "mac"
 [test_corrupt_541828.js]
 [test_corrupt_1211262.js]
 [test_crx.js]
 [test_dirjar_bug525755.js]
 [test_jarinput_stream_zipreader_reference.js]
 [test_not_found.js]
 [test_uncompressed.js]
 [test_umlaute.js]
+[test_bug1328865.js]