Title: [273624] trunk
Revision
273624
Author
[email protected]
Date
2021-02-27 06:25:38 -0800 (Sat, 27 Feb 2021)

Log Message

Null check ArrayBufferView RefPtr
https://bugs.webkit.org/show_bug.cgi?id=221569

Patch by Rob Buis <[email protected]> on 2021-02-27
Reviewed by Ryosuke Niwa.

Source/_javascript_Core:

Null check ArrayBufferView RefPtr before using it.

* runtime/JSArrayBufferViewInlines.h:
(JSC::JSArrayBufferView::unsharedImpl):

LayoutTests:

Add test to verify oom situation does not result in a crash.

* crypto/crypto-random-values-oom-expected.txt: Added.
* crypto/crypto-random-values-oom.html: Added.
* platform/win/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (273623 => 273624)


--- trunk/LayoutTests/ChangeLog	2021-02-27 11:49:03 UTC (rev 273623)
+++ trunk/LayoutTests/ChangeLog	2021-02-27 14:25:38 UTC (rev 273624)
@@ -1,3 +1,16 @@
+2021-02-27  Rob Buis  <[email protected]>
+
+        Null check ArrayBufferView RefPtr
+        https://bugs.webkit.org/show_bug.cgi?id=221569
+
+        Reviewed by Ryosuke Niwa.
+
+        Add test to verify oom situation does not result in a crash.
+
+        * crypto/crypto-random-values-oom-expected.txt: Added.
+        * crypto/crypto-random-values-oom.html: Added.
+        * platform/win/TestExpectations:
+
 2021-02-27  Antti Koivisto  <[email protected]>
 
         Render tree updates for Text node content mutations should happen during rendering update

Added: trunk/LayoutTests/crypto/crypto-random-values-oom-expected.txt (0 => 273624)


--- trunk/LayoutTests/crypto/crypto-random-values-oom-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/crypto-random-values-oom-expected.txt	2021-02-27 14:25:38 UTC (rev 273624)
@@ -0,0 +1,11 @@
+Test crypto.getRandomValues behavior in oom situation.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS exceptionString == undefined || exceptionString === "TypeError: Argument 1 ('array') to Crypto.getRandomValues must be an instance of ArrayBufferView" is true
+PASS crypto.getRandomValues didn't crash
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/crypto-random-values-oom.html (0 => 273624)


--- trunk/LayoutTests/crypto/crypto-random-values-oom.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/crypto-random-values-oom.html	2021-02-27 14:25:38 UTC (rev 273624)
@@ -0,0 +1,44 @@
+<!DOCTYPE HTML><!-- webkit-test-runner [ dumpJSConsoleLogInStdErr=true ] -->
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+</head>
+<body>
+<script>
+description("Test crypto.getRandomValues behavior in oom situation.")
+
+let exceptionString = undefined;
+
+function useAllMemory() {
+    const a = [0];
+    a.__proto__ = {};
+    Object.defineProperty(a, 0, {get: foo});
+    Object.defineProperty(a, 80000000, {});
+
+    function foo() {
+        new Uint8Array(a);
+    }
+
+    new Promise(foo);
+    try {
+        for (let i = 0; i < 2**32; i++) {
+          new ArrayBuffer(1000);
+        }
+    } catch {
+    }
+}
+
+useAllMemory();
+try {
+    crypto.getRandomValues(new Uint8Array());
+} catch (e) {
+    gc();
+    exceptionString = e.toString();
+}
+gc();
+shouldBeTrue("exceptionString == undefined || exceptionString === \"TypeError: Argument 1 ('array') to Crypto.getRandomValues must be an instance of ArrayBufferView\"");
+testPassed("crypto.getRandomValues didn't crash");
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/win/TestExpectations (273623 => 273624)


--- trunk/LayoutTests/platform/win/TestExpectations	2021-02-27 11:49:03 UTC (rev 273623)
+++ trunk/LayoutTests/platform/win/TestExpectations	2021-02-27 14:25:38 UTC (rev 273624)
@@ -4648,3 +4648,6 @@
 fast/css/parsing-color-mix.html [ Failure ]
 fast/css/parsing-relative-color-syntax.html [ Failure ]
 fast/text/letter-spacing-produces-nan-width.html [ Timeout ]
+
+# https://bugs.webkit.org/show_bug.cgi?id=221569
+crypto/crypto-random-values-oom.html [ Skip ]

Modified: trunk/Source/_javascript_Core/ChangeLog (273623 => 273624)


--- trunk/Source/_javascript_Core/ChangeLog	2021-02-27 11:49:03 UTC (rev 273623)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-02-27 14:25:38 UTC (rev 273624)
@@ -1,3 +1,15 @@
+2021-02-27  Rob Buis  <[email protected]>
+
+        Null check ArrayBufferView RefPtr
+        https://bugs.webkit.org/show_bug.cgi?id=221569
+
+        Reviewed by Ryosuke Niwa.
+
+        Null check ArrayBufferView RefPtr before using it.
+
+        * runtime/JSArrayBufferViewInlines.h:
+        (JSC::JSArrayBufferView::unsharedImpl):
+
 2021-02-26  Yusuke Suzuki  <[email protected]>
 
         [JSC] Avoid creating functions unnecessarily in builtins

Modified: trunk/Source/_javascript_Core/runtime/JSArrayBufferViewInlines.h (273623 => 273624)


--- trunk/Source/_javascript_Core/runtime/JSArrayBufferViewInlines.h	2021-02-27 11:49:03 UTC (rev 273623)
+++ trunk/Source/_javascript_Core/runtime/JSArrayBufferViewInlines.h	2021-02-27 14:25:38 UTC (rev 273624)
@@ -76,7 +76,7 @@
 inline RefPtr<ArrayBufferView> JSArrayBufferView::unsharedImpl()
 {
     RefPtr<ArrayBufferView> result = possiblySharedImpl();
-    RELEASE_ASSERT(!result->isShared());
+    RELEASE_ASSERT(!result || !result->isShared());
     return result;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to