Title: [264379] trunk
Revision
264379
Author
mark....@apple.com
Date
2020-07-14 15:51:19 -0700 (Tue, 14 Jul 2020)

Log Message

Handle out of memory error while creating an error message in the literal parser.
https://bugs.webkit.org/show_bug.cgi?id=214313
<rdar://problem/65031745>

Reviewed by Saam Barati.

JSTests:

* stress/out-of-memory-making-error-string-in-literal-parser.js: Added.

Source/_javascript_Core:

* runtime/LiteralParser.cpp:
(JSC::LiteralParser<CharType>::parse):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (264378 => 264379)


--- trunk/JSTests/ChangeLog	2020-07-14 22:50:49 UTC (rev 264378)
+++ trunk/JSTests/ChangeLog	2020-07-14 22:51:19 UTC (rev 264379)
@@ -1,3 +1,13 @@
+2020-07-14  Mark Lam  <mark....@apple.com>
+
+        Handle out of memory error while creating an error message in the literal parser.
+        https://bugs.webkit.org/show_bug.cgi?id=214313
+        <rdar://problem/65031745>
+
+        Reviewed by Saam Barati.
+
+        * stress/out-of-memory-making-error-string-in-literal-parser.js: Added.
+
 2020-07-14  Angelos Oikonomopoulos  <ange...@igalia.com>
 
         Skip intermittently failing type-check-hoisting-phase-hoist-check-structure-on-tdz-this-value on mips

Added: trunk/JSTests/stress/out-of-memory-making-error-string-in-literal-parser.js (0 => 264379)


--- trunk/JSTests/stress/out-of-memory-making-error-string-in-literal-parser.js	                        (rev 0)
+++ trunk/JSTests/stress/out-of-memory-making-error-string-in-literal-parser.js	2020-07-14 22:51:19 UTC (rev 264379)
@@ -0,0 +1,13 @@
+//@ skip if $memoryLimited
+//@ slow!
+//@ runDefault
+
+var exception;
+try {
+    eval("JSON.parse(''.padStart(2 ** 31 - 1, 'a'))");
+} catch (e) {
+    exception = e;
+}
+
+if (exception != 'SyntaxError: JSON Parse error: Unexpected identifier "aaaaaaaaaa..."')
+    throw "FAIL: actual " + exception;

Modified: trunk/Source/_javascript_Core/ChangeLog (264378 => 264379)


--- trunk/Source/_javascript_Core/ChangeLog	2020-07-14 22:50:49 UTC (rev 264378)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-07-14 22:51:19 UTC (rev 264379)
@@ -1,3 +1,14 @@
+2020-07-14  Mark Lam  <mark....@apple.com>
+
+        Handle out of memory error while creating an error message in the literal parser.
+        https://bugs.webkit.org/show_bug.cgi?id=214313
+        <rdar://problem/65031745>
+
+        Reviewed by Saam Barati.
+
+        * runtime/LiteralParser.cpp:
+        (JSC::LiteralParser<CharType>::parse):
+
 2020-07-14  Caitlin Potter  <ca...@igalia.com>
 
         [JSC] fixup LLInt fast path in op_get_private_name

Modified: trunk/Source/_javascript_Core/runtime/LiteralParser.cpp (264378 => 264379)


--- trunk/Source/_javascript_Core/runtime/LiteralParser.cpp	2020-07-14 22:50:49 UTC (rev 264378)
+++ trunk/Source/_javascript_Core/runtime/LiteralParser.cpp	2020-07-14 22:51:19 UTC (rev 264379)
@@ -993,10 +993,23 @@
                         return JSValue();
                     case TokIdentifier: {
                         typename Lexer::LiteralParserTokenPtr token = m_lexer.currentToken();
-                        if (token->stringIs8Bit)
-                            m_parseErrorMessage = makeString("Unexpected identifier \"", StringView { token->stringToken8, token->stringLength }, '"');
-                        else
-                            m_parseErrorMessage = makeString("Unexpected identifier \"", StringView { token->stringToken16, token->stringLength }, '"');
+
+                        auto tryMakeErrorString = [=] (typename Lexer::LiteralParserTokenPtr token, unsigned length, bool addEllipsis) -> String {
+                            if (token->stringIs8Bit)
+                                return tryMakeString("Unexpected identifier \"", StringView { token->stringToken8, length }, addEllipsis ? "..." : "", '"');
+                            return tryMakeString("Unexpected identifier \"", StringView { token->stringToken16, length }, addEllipsis ? "..." : "", '"');
+                        };
+
+                        String errorString = tryMakeErrorString(token, token->stringLength, false);
+                        if (!errorString) {
+                            constexpr unsigned shortLength = 10;
+                            if (token->stringLength > shortLength)
+                                errorString = tryMakeErrorString(token, shortLength, true);
+                            if (!errorString)
+                                errorString = "Unexpected identifier";
+                        }
+
+                        m_parseErrorMessage = errorString;
                         return JSValue();
                     }
                     case TokColon:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to