Bug 638318 - Require all zero bytes to be in either odd or even position when sniffing for UTF-16BE/LE-encoded Basic Latin. r=bz, a=beltzner
authorHenri Sivonen <hsivonen@iki.fi>
Thu, 03 Mar 2011 08:52:47 +0200
changeset 63321 ed9c526f93b5373ff45415ccba4232369c82f645
parent 63320 a6eb991e7f05e82f1361c11412b8e86d43f0a551
child 63322 770e2709cff513f8690c27cd0c78d7a62849847c
push id19144
push userjst@mozilla.com
push dateThu, 03 Mar 2011 17:20:47 +0000
treeherdermozilla-central@ed9c526f93b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, beltzner
bugs638318
milestone2.0b13pre
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 638318 - Require all zero bytes to be in either odd or even position when sniffing for UTF-16BE/LE-encoded Basic Latin. r=bz, a=beltzner
parser/html/nsHtml5StreamParser.cpp
--- a/parser/html/nsHtml5StreamParser.cpp
+++ b/parser/html/nsHtml5StreamParser.cpp
@@ -338,35 +338,46 @@ void
 nsHtml5StreamParser::SniffBOMlessUTF16BasicLatin(const PRUint8* aFromSegment,
                                                  PRUint32 aCountToSniffingLimit)
 {
   // Make sure there's enough data. Require room for "<title></title>"
   if (mSniffingLength + aCountToSniffingLimit < 30) {
     return;
   }
   // even-numbered bytes tracked at 0, odd-numbered bytes tracked at 1
+  PRBool byteZero[2] = { PR_FALSE, PR_FALSE };
   PRBool byteNonZero[2] = { PR_FALSE, PR_FALSE };
   PRUint32 i = 0;
   if (mSniffingBuffer) {
     for (; i < mSniffingLength; ++i) {
       if (mSniffingBuffer[i]) {
         if (byteNonZero[1 - (i % 2)]) {
           return;
         }
         byteNonZero[i % 2] = PR_TRUE;
+      } else {
+        if (byteZero[1 - (i % 2)]) {
+          return;
+        }
+        byteZero[i % 2] = PR_TRUE;
       }
     }
   }
   if (aFromSegment) {
     for (PRUint32 j = 0; j < aCountToSniffingLimit; ++j) {
       if (aFromSegment[j]) {
         if (byteNonZero[1 - ((i + j) % 2)]) {
           return;
         }
         byteNonZero[(i + j) % 2] = PR_TRUE;
+      } else {
+        if (byteZero[1 - ((i + j) % 2)]) {
+          return;
+        }
+        byteZero[(i + j) % 2] = PR_TRUE;
       }
     }
   }
 
   if (byteNonZero[0]) {
     mCharset.Assign("UTF-16LE");
   } else {
     mCharset.Assign("UTF-16BE");