<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[238326] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/238326">238326</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2018-11-16 16:42:44 -0800 (Fri, 16 Nov 2018)</dd>
</dl>

<h3>Log Message</h3>
<pre>All users of ArrayBuffer should agree on the same max size
https://bugs.webkit.org/show_bug.cgi?id=191771

Reviewed by Mark Lam.

JSTests:

* stress/big-wasm-memory-grow-no-max.js: Added.
(foo):
(catch):
* stress/big-wasm-memory-grow.js: Added.
(foo):
(catch):
* stress/big-wasm-memory.js: Added.
(foo):
(catch):

Source/JavaScriptCore:

Array buffers cannot be larger than 0x7fffffff, because otherwise loading typedArray.length in the DFG/FTL would produce
a uint32 or would require a signedness check, neither of which sounds reasonable. It's better to just bound their max size
instead.

* runtime/ArrayBuffer.cpp:
(JSC::ArrayBufferContents::ArrayBufferContents):
(JSC::ArrayBufferContents::tryAllocate):
(JSC::ArrayBufferContents::transferTo):
(JSC::ArrayBufferContents::copyTo):
(JSC::ArrayBufferContents::shareWith):
* runtime/ArrayBuffer.h:
* wasm/WasmMemory.cpp:
(JSC::Wasm::Memory::tryCreate):
(JSC::Wasm::Memory::grow):
* wasm/WasmPageCount.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkJSTestsChangeLog">trunk/JSTests/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeArrayBuffercpp">trunk/Source/JavaScriptCore/runtime/ArrayBuffer.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeArrayBufferh">trunk/Source/JavaScriptCore/runtime/ArrayBuffer.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmMemorycpp">trunk/Source/JavaScriptCore/wasm/WasmMemory.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmjsWebAssemblyMemoryConstructorcpp">trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkJSTestsstressbigwasmmemorygrownomaxjs">trunk/JSTests/stress/big-wasm-memory-grow-no-max.js</a></li>
<li><a href="#trunkJSTestsstressbigwasmmemorygrowjs">trunk/JSTests/stress/big-wasm-memory-grow.js</a></li>
<li><a href="#trunkJSTestsstressbigwasmmemoryjs">trunk/JSTests/stress/big-wasm-memory.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkJSTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/JSTests/ChangeLog (238325 => 238326)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/ChangeLog  2018-11-17 00:31:29 UTC (rev 238325)
+++ trunk/JSTests/ChangeLog     2018-11-17 00:42:44 UTC (rev 238326)
</span><span class="lines">@@ -1,5 +1,22 @@
</span><span class="cx"> 2018-11-16  Filip Pizlo  <fpizlo@apple.com>
</span><span class="cx"> 
</span><ins>+        All users of ArrayBuffer should agree on the same max size
+        https://bugs.webkit.org/show_bug.cgi?id=191771
+
+        Reviewed by Mark Lam.
+
+        * stress/big-wasm-memory-grow-no-max.js: Added.
+        (foo):
+        (catch):
+        * stress/big-wasm-memory-grow.js: Added.
+        (foo):
+        (catch):
+        * stress/big-wasm-memory.js: Added.
+        (foo):
+        (catch):
+
+2018-11-16  Filip Pizlo  <fpizlo@apple.com>
+
</ins><span class="cx">         Unreviewed, make some more tests not crash my computer by only running on instance of it. These tests do not need to
</span><span class="cx">         run for each JSC config since they're regression tests for runtime bugs.
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkJSTestsstressbigwasmmemorygrownomaxjs"></a>
<div class="addfile"><h4>Added: trunk/JSTests/stress/big-wasm-memory-grow-no-max.js (0 => 238326)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/stress/big-wasm-memory-grow-no-max.js                              (rev 0)
+++ trunk/JSTests/stress/big-wasm-memory-grow-no-max.js 2018-11-17 00:42:44 UTC (rev 238326)
</span><span class="lines">@@ -0,0 +1,33 @@
</span><ins>+let bigArray = new Array(0x7000000);
+bigArray[0] = 1.1;
+bigArray[1] = 1.2;
+
+function foo(array) {
+    var index = array.length;
+    if (index >= bigArray.length || (index - 0x1ffdc01) < 0)
+        return;
+    return bigArray[index - 0x1ffdc01];
+}
+
+noInline(foo);
+
+var okArray = new Uint8Array(0x1ffdc02);
+
+for (var i = 0; i < 10000; ++i)
+    foo(okArray);
+
+var ok = false;
+try {
+    var memory = new WebAssembly.Memory({ initial: 0x1000 });
+    memory.grow(0x7000);
+    var result = foo(new Uint8Array(memory.buffer));
+    if (result !== void 0)
+        throw "Error: bad result at end: " + result;
+    ok = true;
+} catch (e) {
+    if (e.toString() != "RangeError: WebAssembly.Memory.grow expects the grown size to be a valid page count")
+        throw e;
+}
+
+if (ok)
+    throw "Error: did not throw error";
</ins></span></pre></div>
<a id="trunkJSTestsstressbigwasmmemorygrowjs"></a>
<div class="addfile"><h4>Added: trunk/JSTests/stress/big-wasm-memory-grow.js (0 => 238326)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/stress/big-wasm-memory-grow.js                             (rev 0)
+++ trunk/JSTests/stress/big-wasm-memory-grow.js        2018-11-17 00:42:44 UTC (rev 238326)
</span><span class="lines">@@ -0,0 +1,33 @@
</span><ins>+let bigArray = new Array(0x7000000);
+bigArray[0] = 1.1;
+bigArray[1] = 1.2;
+
+function foo(array) {
+    var index = array.length;
+    if (index >= bigArray.length || (index - 0x1ffdc01) < 0)
+        return;
+    return bigArray[index - 0x1ffdc01];
+}
+
+noInline(foo);
+
+var okArray = new Uint8Array(0x1ffdc02);
+
+for (var i = 0; i < 10000; ++i)
+    foo(okArray);
+
+var ok = false;
+try {
+    var memory = new WebAssembly.Memory({ initial: 0x1000, maximum: 0x8000 });
+    memory.grow(0x7000);
+    var result = foo(new Uint8Array(memory.buffer));
+    if (result !== void 0)
+        throw "Error: bad result at end: " + result;
+    ok = true;
+} catch (e) {
+    if (e.toString() != "RangeError: WebAssembly.Memory.grow expects the grown size to be a valid page count")
+        throw e;
+}
+
+if (ok)
+    throw "Error: did not throw error";
</ins></span></pre></div>
<a id="trunkJSTestsstressbigwasmmemoryjs"></a>
<div class="addfile"><h4>Added: trunk/JSTests/stress/big-wasm-memory.js (0 => 238326)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/stress/big-wasm-memory.js                          (rev 0)
+++ trunk/JSTests/stress/big-wasm-memory.js     2018-11-17 00:42:44 UTC (rev 238326)
</span><span class="lines">@@ -0,0 +1,31 @@
</span><ins>+let bigArray = new Array(0x7000000);
+bigArray[0] = 1.1;
+bigArray[1] = 1.2;
+
+function foo(array) {
+    var index = array.length;
+    if (index >= bigArray.length || (index - 0x1ffdc01) < 0)
+        return;
+    return bigArray[index - 0x1ffdc01];
+}
+
+noInline(foo);
+
+var okArray = new Uint8Array(0x1ffdc02);
+
+for (var i = 0; i < 10000; ++i)
+    foo(okArray);
+
+var ok = false;
+try {
+    var result = foo(new Uint8Array(new WebAssembly.Memory({ initial: 0x8000, maximum: 0x8000 }).buffer));
+    if (result !== void 0)
+        throw "Error: bad result at end: " + result;
+    ok = true;
+} catch (e) {
+    if (e.toString() != "RangeError: WebAssembly.Memory 'initial' page count is too large")
+        throw e;
+}
+
+if (ok)
+    throw "Error: did not throw error";
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (238325 => 238326)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog    2018-11-17 00:31:29 UTC (rev 238325)
+++ trunk/Source/JavaScriptCore/ChangeLog       2018-11-17 00:42:44 UTC (rev 238326)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2018-11-16  Filip Pizlo  <fpizlo@apple.com>
+
+        All users of ArrayBuffer should agree on the same max size
+        https://bugs.webkit.org/show_bug.cgi?id=191771
+
+        Reviewed by Mark Lam.
+
+        Array buffers cannot be larger than 0x7fffffff, because otherwise loading typedArray.length in the DFG/FTL would produce
+        a uint32 or would require a signedness check, neither of which sounds reasonable. It's better to just bound their max size
+        instead.
+
+        * runtime/ArrayBuffer.cpp:
+        (JSC::ArrayBufferContents::ArrayBufferContents):
+        (JSC::ArrayBufferContents::tryAllocate):
+        (JSC::ArrayBufferContents::transferTo):
+        (JSC::ArrayBufferContents::copyTo):
+        (JSC::ArrayBufferContents::shareWith):
+        * runtime/ArrayBuffer.h:
+        * wasm/WasmMemory.cpp:
+        (JSC::Wasm::Memory::tryCreate):
+        (JSC::Wasm::Memory::grow):
+        * wasm/WasmPageCount.h:
+
</ins><span class="cx"> 2018-11-16  Saam Barati  <sbarati@apple.com>
</span><span class="cx"> 
</span><span class="cx">         KnownCellUse should also have SpecCellCheck as its type filter
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeArrayBuffercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ArrayBuffer.cpp (238325 => 238326)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ArrayBuffer.cpp      2018-11-17 00:31:29 UTC (rev 238325)
+++ trunk/Source/JavaScriptCore/runtime/ArrayBuffer.cpp 2018-11-17 00:42:44 UTC (rev 238326)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2009-2017 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2009-2018 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx">     : m_data(data)
</span><span class="cx">     , m_sizeInBytes(sizeInBytes)
</span><span class="cx"> {
</span><ins>+    RELEASE_ASSERT(m_sizeInBytes <= MAX_ARRAY_BUFFER_SIZE);
</ins><span class="cx">     m_destructor = WTFMove(destructor);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -97,8 +98,7 @@
</span><span class="cx">     // Do not allow 31-bit overflow of the total size.
</span><span class="cx">     if (numElements) {
</span><span class="cx">         unsigned totalSize = numElements * elementByteSize;
</span><del>-        if (totalSize / numElements != elementByteSize
-            || totalSize > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) {
</del><ins>+        if (totalSize / numElements != elementByteSize || totalSize > MAX_ARRAY_BUFFER_SIZE) {
</ins><span class="cx">             reset();
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="lines">@@ -116,6 +116,7 @@
</span><span class="cx">         memset(m_data.get(), 0, size);
</span><span class="cx"> 
</span><span class="cx">     m_sizeInBytes = numElements * elementByteSize;
</span><ins>+    RELEASE_ASSERT(m_sizeInBytes <= MAX_ARRAY_BUFFER_SIZE);
</ins><span class="cx">     m_destructor = [] (void* p) { Gigacage::free(Gigacage::Primitive, p); };
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -130,6 +131,7 @@
</span><span class="cx">     other.clear();
</span><span class="cx">     other.m_data = m_data;
</span><span class="cx">     other.m_sizeInBytes = m_sizeInBytes;
</span><ins>+    RELEASE_ASSERT(other.m_sizeInBytes <= MAX_ARRAY_BUFFER_SIZE);
</ins><span class="cx">     other.m_destructor = WTFMove(m_destructor);
</span><span class="cx">     other.m_shared = m_shared;
</span><span class="cx">     reset();
</span><span class="lines">@@ -143,6 +145,7 @@
</span><span class="cx">         return;
</span><span class="cx">     memcpy(other.m_data.get(), m_data.get(), m_sizeInBytes);
</span><span class="cx">     other.m_sizeInBytes = m_sizeInBytes;
</span><ins>+    RELEASE_ASSERT(other.m_sizeInBytes <= MAX_ARRAY_BUFFER_SIZE);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ArrayBufferContents::shareWith(ArrayBufferContents& other)
</span><span class="lines">@@ -153,6 +156,7 @@
</span><span class="cx">     other.m_shared = m_shared;
</span><span class="cx">     other.m_data = m_data;
</span><span class="cx">     other.m_sizeInBytes = m_sizeInBytes;
</span><ins>+    RELEASE_ASSERT(other.m_sizeInBytes <= MAX_ARRAY_BUFFER_SIZE);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Ref<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeArrayBufferh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ArrayBuffer.h (238325 => 238326)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ArrayBuffer.h        2018-11-17 00:31:29 UTC (rev 238325)
+++ trunk/Source/JavaScriptCore/runtime/ArrayBuffer.h   2018-11-17 00:42:44 UTC (rev 238326)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2009-2017 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2009-2018 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -36,6 +36,8 @@
</span><span class="cx"> 
</span><span class="cx"> namespace JSC {
</span><span class="cx"> 
</span><ins>+#define MAX_ARRAY_BUFFER_SIZE 0x7fffffffu
+
</ins><span class="cx"> class VM;
</span><span class="cx"> class ArrayBuffer;
</span><span class="cx"> class ArrayBufferView;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmMemorycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmMemory.cpp (238325 => 238326)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmMemory.cpp  2018-11-17 00:31:29 UTC (rev 238325)
+++ trunk/Source/JavaScriptCore/wasm/WasmMemory.cpp     2018-11-17 00:42:44 UTC (rev 238326)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016-2018 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -282,6 +282,8 @@
</span><span class="cx">     const size_t initialBytes = initial.bytes();
</span><span class="cx">     const size_t maximumBytes = maximum ? maximum.bytes() : 0;
</span><span class="cx"> 
</span><ins>+    RELEASE_ASSERT(initialBytes <= MAX_ARRAY_BUFFER_SIZE);
+
</ins><span class="cx">     if (maximum && !maximumBytes) {
</span><span class="cx">         // User specified a zero maximum, initial size must also be zero.
</span><span class="cx">         RELEASE_ASSERT(!initialBytes);
</span><span class="lines">@@ -372,7 +374,10 @@
</span><span class="cx">         return makeUnexpected(GrowFailReason::InvalidDelta);
</span><span class="cx">     
</span><span class="cx">     const Wasm::PageCount newPageCount = oldPageCount + delta;
</span><del>-    if (!newPageCount)
</del><ins>+    // FIXME: Creating a wasm memory that is bigger than the ArrayBuffer limit but smaller than the spec limit should throw
+    // OOME not RangeError
+    // https://bugs.webkit.org/show_bug.cgi?id=191776
+    if (!newPageCount || !newPageCount.isValid() || newPageCount.bytes() >= MAX_ARRAY_BUFFER_SIZE)
</ins><span class="cx">         return makeUnexpected(GrowFailReason::InvalidGrowSize);
</span><span class="cx"> 
</span><span class="cx">     auto success = [&] () {
</span><span class="lines">@@ -395,6 +400,7 @@
</span><span class="cx">         return makeUnexpected(GrowFailReason::WouldExceedMaximum);
</span><span class="cx"> 
</span><span class="cx">     size_t desiredSize = newPageCount.bytes();
</span><ins>+    RELEASE_ASSERT(desiredSize <= MAX_ARRAY_BUFFER_SIZE);
</ins><span class="cx">     RELEASE_ASSERT(desiredSize > m_size);
</span><span class="cx">     size_t extraBytes = desiredSize - m_size;
</span><span class="cx">     RELEASE_ASSERT(extraBytes);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmjsWebAssemblyMemoryConstructorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp (238325 => 238326)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp     2018-11-17 00:31:29 UTC (rev 238325)
+++ trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp        2018-11-17 00:42:44 UTC (rev 238326)
</span><span class="lines">@@ -70,7 +70,10 @@
</span><span class="cx">         RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
</span><span class="cx">         uint32_t size = toNonWrappingUint32(exec, minSizeValue);
</span><span class="cx">         RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
</span><del>-        if (!Wasm::PageCount::isValid(size))
</del><ins>+        // FIXME: Creating a wasm memory that is bigger than the ArrayBuffer limit but smaller than the spec limit should throw
+        // OOME not RangeError
+        // https://bugs.webkit.org/show_bug.cgi?id=191776
+        if (!Wasm::PageCount::isValid(size) || Wasm::PageCount(size).bytes() >= MAX_ARRAY_BUFFER_SIZE)
</ins><span class="cx">             return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, "WebAssembly.Memory 'initial' page count is too large"_s)));
</span><span class="cx">         initialPageCount = Wasm::PageCount(size);
</span><span class="cx">     }
</span></span></pre>
</div>
</div>

</body>
</html>