Title: [287711] trunk
Revision
287711
Author
[email protected]
Date
2022-01-06 12:13:31 -0800 (Thu, 06 Jan 2022)

Log Message

ReadableStream::lock should check whether there is an exception when getting ReadableStreamDefaultReader private constructor
https://bugs.webkit.org/show_bug.cgi?id=234890

Source/WebCore:

Reviewed by Frédéric Wang and Mark Lam.

Do in ReadableStream::lock like we are doing when getting ReadableStream private constructor in ReadableStream::create.
For that reason, introduce a invokeConstructor utility function.

Test: streams/readable-stream-lock-after-worker-terminates-crash.html

* bindings/js/ReadableStream.cpp:

LayoutTests:

Reviewed by Frédéric Wang.

* streams/readable-stream-lock-after-worker-terminates-crash-expected.txt: Added.
* streams/readable-stream-lock-after-worker-terminates-crash.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (287710 => 287711)


--- trunk/LayoutTests/ChangeLog	2022-01-06 20:04:41 UTC (rev 287710)
+++ trunk/LayoutTests/ChangeLog	2022-01-06 20:13:31 UTC (rev 287711)
@@ -1,3 +1,13 @@
+2022-01-06  Youenn Fablet  <[email protected]>
+
+        ReadableStream::lock should check whether there is an exception when getting ReadableStreamDefaultReader private constructor
+        https://bugs.webkit.org/show_bug.cgi?id=234890
+
+        Reviewed by Frédéric Wang.
+
+        * streams/readable-stream-lock-after-worker-terminates-crash-expected.txt: Added.
+        * streams/readable-stream-lock-after-worker-terminates-crash.html: Added.
+
 2022-01-06  Said Abou-Hallawa  <[email protected]>
 
         REGRESSION(r285618):A crash may happen when calculating the color-interpolation of a referenced SVG filter

Added: trunk/LayoutTests/streams/readable-stream-lock-after-worker-terminates-crash-expected.txt (0 => 287711)


--- trunk/LayoutTests/streams/readable-stream-lock-after-worker-terminates-crash-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/streams/readable-stream-lock-after-worker-terminates-crash-expected.txt	2022-01-06 20:13:31 UTC (rev 287711)
@@ -0,0 +1,2 @@
+CONSOLE MESSAGE: This test PASS if it does not crash.
+

Added: trunk/LayoutTests/streams/readable-stream-lock-after-worker-terminates-crash.html (0 => 287711)


--- trunk/LayoutTests/streams/readable-stream-lock-after-worker-terminates-crash.html	                        (rev 0)
+++ trunk/LayoutTests/streams/readable-stream-lock-after-worker-terminates-crash.html	2022-01-06 20:13:31 UTC (rev 287711)
@@ -0,0 +1,30 @@
+<script>
+function createWorker() {
+    function createRequest() {
+        setTimeout(() => {
+            const request = new Request("http://test.org", {"method": "POST", "body": "text" });
+            request.text();
+            request.body;
+        }, 0);
+        self.postMessage("");
+    };
+    const worker = new Worker('data:application/_javascript_;charset=utf-8,' + createRequest.toString() + ';createRequest()');
+    return new Promise(resolve => {
+        worker._onmessage_ = () => {
+            worker.terminate();
+            resolve();
+        }
+    });
+}
+
+_onload_ = () => {
+    if (window.testRunner)
+        testRunner.dumpAsText();
+    console.log('This test PASS if it does not crash.')
+    for (var i = 0; i < 100; ++i) {
+        const script = document.createElement('script');
+        script.src = ""
+        document.head.appendChild(script);
+    }
+};
+</script>

Modified: trunk/Source/WebCore/ChangeLog (287710 => 287711)


--- trunk/Source/WebCore/ChangeLog	2022-01-06 20:04:41 UTC (rev 287710)
+++ trunk/Source/WebCore/ChangeLog	2022-01-06 20:13:31 UTC (rev 287711)
@@ -1,3 +1,17 @@
+2022-01-06  Youenn Fablet  <[email protected]>
+
+        ReadableStream::lock should check whether there is an exception when getting ReadableStreamDefaultReader private constructor
+        https://bugs.webkit.org/show_bug.cgi?id=234890
+
+        Reviewed by Frédéric Wang and Mark Lam.
+
+        Do in ReadableStream::lock like we are doing when getting ReadableStream private constructor in ReadableStream::create.
+        For that reason, introduce a invokeConstructor utility function.
+
+        Test: streams/readable-stream-lock-after-worker-terminates-crash.html
+
+        * bindings/js/ReadableStream.cpp:
+
 2022-01-06  Said Abou-Hallawa  <[email protected]>
 
         REGRESSION(r285618):A crash may happen when calculating the color-interpolation of a referenced SVG filter

Modified: trunk/Source/WebCore/bindings/js/ReadableStream.cpp (287710 => 287711)


--- trunk/Source/WebCore/bindings/js/ReadableStream.cpp	2022-01-06 20:04:41 UTC (rev 287710)
+++ trunk/Source/WebCore/bindings/js/ReadableStream.cpp	2022-01-06 20:13:31 UTC (rev 287711)
@@ -37,15 +37,15 @@
 namespace WebCore {
 using namespace JSC;
 
-ExceptionOr<Ref<ReadableStream>> ReadableStream::create(JSC::JSGlobalObject& lexicalGlobalObject, RefPtr<ReadableStreamSource>&& source)
+static inline ExceptionOr<JSObject*> invokeConstructor(JSC::JSGlobalObject& lexicalGlobalObject, const JSC::Identifier& identifier, const Function<void(MarkedArgumentBuffer&, JSC::JSGlobalObject&, JSDOMGlobalObject&)>& buildArguments)
 {
     VM& vm = lexicalGlobalObject.vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
 
-    auto& clientData = *static_cast<JSVMClientData*>(vm.clientData);
     auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject);
 
-    auto constructorValue = globalObject.get(&lexicalGlobalObject, clientData.builtinNames().ReadableStreamPrivateName());
+    auto constructorValue = globalObject.get(&lexicalGlobalObject, identifier);
+    EXCEPTION_ASSERT(!scope.exception() || vm.hasPendingTerminationException());
     RETURN_IF_EXCEPTION(scope, Exception { ExistingExceptionError });
     auto constructor = JSC::asObject(constructorValue);
 
@@ -53,16 +53,31 @@
     ASSERT(constructData.type != CallData::Type::None);
 
     MarkedArgumentBuffer args;
-    args.append(source ? toJSNewlyCreated(&lexicalGlobalObject, &globalObject, source.releaseNonNull()) : JSC::jsUndefined());
+    buildArguments(args, lexicalGlobalObject, globalObject);
     ASSERT(!args.hasOverflowed());
 
     JSObject* object = JSC::construct(&lexicalGlobalObject, constructor, constructData, args);
     ASSERT(!!scope.exception() == !object);
+    EXCEPTION_ASSERT(!scope.exception() || vm.hasPendingTerminationException());
     RETURN_IF_EXCEPTION(scope, Exception { ExistingExceptionError });
 
-    return create(globalObject, *jsCast<JSReadableStream*>(object));
+    return object;
 }
 
+ExceptionOr<Ref<ReadableStream>> ReadableStream::create(JSC::JSGlobalObject& lexicalGlobalObject, RefPtr<ReadableStreamSource>&& source)
+{
+    auto& clientData = *static_cast<JSVMClientData*>(lexicalGlobalObject.vm().clientData);
+
+    auto objectOrException = invokeConstructor(lexicalGlobalObject, clientData.builtinNames().ReadableStreamPrivateName(), [&source](auto& args, auto& lexicalGlobalObject, auto& globalObject) {
+        args.append(source ? toJSNewlyCreated(&lexicalGlobalObject, &globalObject, source.releaseNonNull()) : JSC::jsUndefined());
+    });
+
+    if (objectOrException.hasException())
+        return objectOrException.releaseException();
+
+    return create(*JSC::jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject), *jsCast<JSReadableStream*>(objectOrException.releaseReturnValue()));
+}
+
 static inline std::optional<JSC::JSValue> invokeReadableStreamFunction(JSC::JSGlobalObject& lexicalGlobalObject, const JSC::Identifier& identifier, JSC::JSValue thisValue, const JSC::MarkedArgumentBuffer& arguments)
 {
     JSC::VM& vm = lexicalGlobalObject.vm();
@@ -115,26 +130,10 @@
 
 void ReadableStream::lock()
 {
-    auto& lexicalGlobalObject = *m_globalObject;
-    auto& vm = lexicalGlobalObject.vm();
-    auto scope = DECLARE_CATCH_SCOPE(vm);
-
-    auto& clientData = *static_cast<JSVMClientData*>(vm.clientData);
-
-    auto* constructor = JSC::asObject(m_globalObject->get(&lexicalGlobalObject, clientData.builtinNames().ReadableStreamDefaultReaderPrivateName()));
-    EXCEPTION_ASSERT(!scope.exception() || vm.hasPendingTerminationException());
-    if (scope.exception())
-        return;
-
-    auto constructData = getConstructData(vm, constructor);
-    ASSERT(constructData.type != CallData::Type::None);
-
-    MarkedArgumentBuffer args;
-    args.append(readableStream());
-    ASSERT(!args.hasOverflowed());
-
-    JSC::construct(&lexicalGlobalObject, constructor, constructData, args);
-    EXCEPTION_ASSERT(!scope.exception() || vm.hasPendingTerminationException());
+    auto& clientData = *static_cast<JSVMClientData*>(m_globalObject->vm().clientData);
+    invokeConstructor(*m_globalObject, clientData.builtinNames().ReadableStreamDefaultReaderPrivateName(), [this](auto& args, auto&, auto&) {
+        args.append(readableStream());
+    });
 }
 
 static inline bool checkReadableStream(JSDOMGlobalObject& globalObject, JSReadableStream* readableStream, JSC::JSValue function)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to