Bug 638112 - Assertion failure: chars[length] == jschar(0). r=dbaron
authorMats Palmgren <matspal@gmail.com>
Wed, 11 May 2011 11:46:59 +0200
changeset 69323 639df63f952ebac6ab0f3cf6bfecc0c5a38f2141
parent 69322 86849e5fb7ca9ddc77026a941358611866ab1410
child 69330 41e9e034e974895ce1d659dd1135d3471994790b
push id19922
push usermpalmgren@mozilla.com
push dateWed, 11 May 2011 09:48:12 +0000
treeherdermozilla-central@639df63f952e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs638112
milestone6.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 638112 - Assertion failure: chars[length] == jschar(0). r=dbaron
content/base/test/Makefile.in
content/base/test/bug638112-response.txt
content/base/test/bug638112.sjs
content/base/test/test_bug638112.html
xpcom/string/public/nsUTF8Utils.h
--- a/content/base/test/Makefile.in
+++ b/content/base/test/Makefile.in
@@ -472,16 +472,19 @@ include $(topsrcdir)/config/rules.mk
 		test_bug631615.html \
 		test_bug558431.html \
 		file_bug558431.html \
 		file_bug558431.html^headers^ \
 		test_bug604592.html \
 		test_bug628938.html \
 		test_bug626262.html \
 		test_plugin_freezing.html \
+		test_bug638112.html \
+		bug638112-response.txt \
+		bug638112.sjs \
 		$(NULL)
 
 # This test fails on the Mac for some reason
 ifneq (,$(filter gtk2 windows,$(MOZ_WIDGET_TOOLKIT)))
 _TEST_FILES2 += 	test_copyimage.html \
 		$(NULL)
 endif
 
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..9ce788da792d9a02133cb7b2bb857152469c5ace
GIT binary patch
literal 247
zc$`I!T?)c55QGI^B#<+>2e4}D4;b*FsHmtQ7<><PZ3A{w>Q>Y%cv5d+6{Pbx%r`SD
zWA;7ORS@<Eu%@#wGRw{r94uXfsAOL_eoHa8j2cW@cAyIGY*7J9fg0*?tW^lhosr^b
zi-(3Njxpz8L9stMN~D;1Vx-#9kUU*p`&*=hQ(ZMmu|dp(=;ChG8oLaA$<t8>GJBtn
lC*hAFjK2>x)Y-brJn}DzckZQ}U8Inr{c1ISYBn2xeE{I$N9F(k
new file mode 100644
--- /dev/null
+++ b/content/base/test/bug638112.sjs
@@ -0,0 +1,26 @@
+function getInputStream(path)
+{
+  var file = Components.classes["@mozilla.org/file/directory_service;1"].
+                        getService(Components.interfaces.nsIProperties).
+                        get("CurWorkD", Components.interfaces.nsILocalFile);
+  var fis  = Components.classes['@mozilla.org/network/file-input-stream;1'].
+                        createInstance(Components.interfaces.nsIFileInputStream);
+  var split = path.split("/");
+  for(var i = 0; i < split.length; ++i) {
+    file.append(split[i]);
+  }
+  fis.init(file, -1, -1, false);
+  return fis;
+}
+
+
+
+function handleRequest(request, response)
+{
+  var inputStream = getInputStream("tests/content/base/test/bug638112-response.txt")
+  response.seizePower();
+  response.bodyOutputStream.writeFrom(inputStream,
+                                      inputStream.available());
+  response.finish();
+  inputStream.close();
+}
new file mode 100644
--- /dev/null
+++ b/content/base/test/test_bug638112.html
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=638112
+-->
+<head>
+  <title>Test for Bug 638112</title>
+  <script type="text/javascript" src="/MochiKit/packed.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=638112">Mozilla Bug 638112</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script type="text/javascript">
+
+/** Test for Bug 638112 **/
+
+function run_test() {
+  var req = new XMLHttpRequest();
+  req.open("GET", "bug638112.sjs", false);
+  req.send(null);
+  var statusText = req.statusText;
+
+  is(statusText, "Information Sans-Autorit", "");
+
+  SimpleTest.finish();
+}
+
+
+SimpleTest.waitForExplicitFinish();
+
+addLoadEvent(run_test);
+
+</script>
+</pre>
+</body>
+</html>
--- a/xpcom/string/public/nsUTF8Utils.h
+++ b/xpcom/string/public/nsUTF8Utils.h
@@ -438,24 +438,26 @@ class CalculateUTF8Length
                 }
 
                 p += 4;
             }
             else if ( UTF8traits::is5byte(*p) )
                 p += 5;
             else if ( UTF8traits::is6byte(*p) )
                 p += 6;
-            else
+            else // error
               {
+                ++mLength; // to account for the decrement below
                 break;
               }
           }
         if ( p != end )
           {
             NS_ERROR("Not a UTF-8 string. This code should only be used for converting from known UTF-8 strings.");
+            --mLength; // The last multi-byte char wasn't complete, discard it.
             mErrorEncountered = PR_TRUE;
           }
       }
 
     private:
       size_t mLength;
       PRBool mErrorEncountered;
   };