Bug 1437004 - Fixing null string behavior in BinAST tokenizer;r?arai,jorendorff
authorDavid Teller <dteller@mozilla.com>
Wed, 21 Feb 2018 16:27:22 +0100
changeset 770036 bb37239238c37896d7c33bf5a9538e0f61ff4e78
parent 770035 235a5b9b02efefb00a294e286655baee4220ff62
child 770037 db9921710ab6ee74052cdee35985db3858ccd015
child 777220 daf42f58ea93817e019328e6e3856f810939a480
push id103291
push userdteller@mozilla.com
push dateTue, 20 Mar 2018 15:29:40 +0000
reviewersarai, jorendorff
bugs1437004
milestone61.0a1
Bug 1437004 - Fixing null string behavior in BinAST tokenizer;r?arai,jorendorff MozReview-Commit-ID: AH91BMcoZsB
js/src/frontend/BinTokenReaderTester.cpp
--- a/js/src/frontend/BinTokenReaderTester.cpp
+++ b/js/src/frontend/BinTokenReaderTester.cpp
@@ -195,33 +195,30 @@ BinTokenReaderTester::readMaybeChars(May
 
     // 2. Reject if we can't read
     if (current_ + byteLen < current_) // Check for overflows
         return raiseError("Arithmetics overflow: string is too long");
 
     if (current_ + byteLen > stop_)
         return raiseError("Not enough bytes to read chars");
 
-    // 3. Check null string (no allocation)
     if (byteLen == 2 && *current_ == 255 && *(current_ + 1) == 0) {
-        // Special case: null string.
+        // 3. Special case: null string.
         out = Nothing();
-        current_ += byteLen;
-        return true;
+    } else {
+        // 4. Other strings (bytes are copied)
+        out.emplace(cx_);
+        if (!out->resize(byteLen)) {
+            ReportOutOfMemory(cx_);
+            return false;
+        }
+        PodCopy(out->begin(), current_, byteLen);
     }
 
-    // 4. Other strings (bytes are copied)
-    out.emplace(cx_);
-    if (!out->resize(byteLen)) {
-        ReportOutOfMemory(cx_);
-        return false;
-    }
-    PodCopy(out->begin(), current_, byteLen);
     current_ += byteLen;
-
     if (!readConst("</string>"))
         return false;
 
     return true;
 }
 
 bool
 BinTokenReaderTester::readChars(Chars& out)