Bug 1437004 - Fixing null string behavior in BinAST tokenizer;r?arai,jorendorff draft
authorDavid Teller <dteller@mozilla.com>
Wed, 21 Feb 2018 16:27:22 +0100
changeset 777852 3be52f7bb42088899f3b7166101feffc8d98a3e6
parent 777851 057da8c4199f92c52d4e950d9142a18a2a83d54b
child 777853 5e1e5a563ef009d94ef6fbedf35501662eeae794
child 778385 615bd81d5ad137e57793f142e4f348d39ce34cf0
child 778389 f78b35a6cb8bcc717fe09b8a200ac3eb8fee314f
push id105306
push userdteller@mozilla.com
push dateThu, 05 Apr 2018 12:07:57 +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)