- Revision
- 243246
- Author
- [email protected]
- Date
- 2019-03-20 15:12:12 -0700 (Wed, 20 Mar 2019)
Log Message
JSC::createError needs to check for OOM in errorDescriptionForValue
https://bugs.webkit.org/show_bug.cgi?id=196032
<rdar://problem/46842740>
Reviewed by Mark Lam.
JSTests:
* stress/create-error-out-of-memory-rope-string.js: Added.
Source/_javascript_Core:
We were missing exceptions checks at two levels:
- In errorDescriptionForValue, when the value is a string, we should
check that JSString::value returns a valid string, since we might run
out of memory if it is a rope and we need to resolve it.
- In createError, we should check for the result of errorDescriptionForValue
before concatenating it with the message provided by the caller.
* runtime/ExceptionHelpers.cpp:
(JSC::errorDescriptionForValue):
(JSC::createError):
* runtime/ExceptionHelpers.h:
Modified Paths
Added Paths
Diff
Modified: trunk/JSTests/ChangeLog (243245 => 243246)
--- trunk/JSTests/ChangeLog 2019-03-20 22:04:15 UTC (rev 243245)
+++ trunk/JSTests/ChangeLog 2019-03-20 22:12:12 UTC (rev 243246)
@@ -1,3 +1,13 @@
+2019-03-20 Tadeu Zagallo <[email protected]>
+
+ JSC::createError needs to check for OOM in errorDescriptionForValue
+ https://bugs.webkit.org/show_bug.cgi?id=196032
+ <rdar://problem/46842740>
+
+ Reviewed by Mark Lam.
+
+ * stress/create-error-out-of-memory-rope-string.js: Added.
+
2019-03-19 Yusuke Suzuki <[email protected]>
Unreviewed, reduce # of iterations to avoid timing out after r242991
Added: trunk/JSTests/stress/create-error-out-of-memory-rope-string.js (0 => 243246)
--- trunk/JSTests/stress/create-error-out-of-memory-rope-string.js (rev 0)
+++ trunk/JSTests/stress/create-error-out-of-memory-rope-string.js 2019-03-20 22:12:12 UTC (rev 243246)
@@ -0,0 +1,3 @@
+var foo = 'yy?x\uFFFD$w 5?\uFFFDo\uFFFD?\uFFFD\'i?\uFFFDE-N\uFFFD\uFFFD6_\uFFFD\\ d';
+foo = foo.padEnd(2147483644, 1);
+eval('foo()');
Modified: trunk/Source/_javascript_Core/ChangeLog (243245 => 243246)
--- trunk/Source/_javascript_Core/ChangeLog 2019-03-20 22:04:15 UTC (rev 243245)
+++ trunk/Source/_javascript_Core/ChangeLog 2019-03-20 22:12:12 UTC (rev 243246)
@@ -1,3 +1,23 @@
+2019-03-20 Tadeu Zagallo <[email protected]>
+
+ JSC::createError needs to check for OOM in errorDescriptionForValue
+ https://bugs.webkit.org/show_bug.cgi?id=196032
+ <rdar://problem/46842740>
+
+ Reviewed by Mark Lam.
+
+ We were missing exceptions checks at two levels:
+ - In errorDescriptionForValue, when the value is a string, we should
+ check that JSString::value returns a valid string, since we might run
+ out of memory if it is a rope and we need to resolve it.
+ - In createError, we should check for the result of errorDescriptionForValue
+ before concatenating it with the message provided by the caller.
+
+ * runtime/ExceptionHelpers.cpp:
+ (JSC::errorDescriptionForValue):
+ (JSC::createError):
+ * runtime/ExceptionHelpers.h:
+
2019-03-20 Devin Rousso <[email protected]>
Web Inspector: DOM: include window as part of any event listener chain
Modified: trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp (243245 => 243246)
--- trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp 2019-03-20 22:04:15 UTC (rev 243245)
+++ trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp 2019-03-20 22:12:12 UTC (rev 243246)
@@ -89,21 +89,26 @@
return createReferenceError(exec, message);
}
-JSString* errorDescriptionForValue(ExecState* exec, JSValue v)
+String errorDescriptionForValue(ExecState* exec, JSValue v)
{
- if (v.isString())
- return jsNontrivialString(exec, makeString('"', asString(v)->value(exec), '"'));
+ if (v.isString()) {
+ String string = asString(v)->value(exec);
+ if (!string)
+ return string;
+ return tryMakeString('"', string, '"');
+ }
+
if (v.isSymbol())
- return jsNontrivialString(exec, asSymbol(v)->descriptiveString());
+ return asSymbol(v)->descriptiveString();
if (v.isObject()) {
VM& vm = exec->vm();
CallData callData;
JSObject* object = asObject(v);
if (object->methodTable(vm)->getCallData(object, callData) != CallType::None)
- return vm.smallStrings.functionString();
- return jsString(exec, JSObject::calculatedClassName(object));
+ return vm.smallStrings.functionString()->value(exec);
+ return JSObject::calculatedClassName(object);
}
- return v.toString(exec);
+ return v.toString(exec)->value(exec);
}
static String defaultApproximateSourceError(const String& originalMessage, const String& sourceText)
@@ -269,9 +274,12 @@
VM& vm = exec->vm();
auto scope = DECLARE_CATCH_SCOPE(vm);
- String errorMessage = tryMakeString(errorDescriptionForValue(exec, value)->value(exec), ' ', message);
- if (errorMessage.isNull())
+ String valueDescription = errorDescriptionForValue(exec, value);
+ if (!valueDescription)
return createOutOfMemoryError(exec);
+ String errorMessage = tryMakeString(valueDescription, ' ', message);
+ if (!errorMessage)
+ return createOutOfMemoryError(exec);
scope.assertNoException();
JSObject* exception = createTypeError(exec, errorMessage, appender, runtimeTypeForValue(vm, value));
ASSERT(exception->isErrorInstance());
Modified: trunk/Source/_javascript_Core/runtime/ExceptionHelpers.h (243245 => 243246)
--- trunk/Source/_javascript_Core/runtime/ExceptionHelpers.h 2019-03-20 22:04:15 UTC (rev 243245)
+++ trunk/Source/_javascript_Core/runtime/ExceptionHelpers.h 2019-03-20 22:12:12 UTC (rev 243246)
@@ -54,7 +54,7 @@
JSObject* createNotAConstructorError(ExecState*, JSValue);
JSObject* createNotAFunctionError(ExecState*, JSValue);
JSObject* createErrorForInvalidGlobalAssignment(ExecState*, const String&);
-JSString* errorDescriptionForValue(ExecState*, JSValue);
+String errorDescriptionForValue(ExecState*, JSValue);
JS_EXPORT_PRIVATE Exception* throwOutOfMemoryError(ExecState*, ThrowScope&);
JS_EXPORT_PRIVATE Exception* throwStackOverflowError(ExecState*, ThrowScope&);