Skip to content

Commit 3a638a5

Browse files
Ben L. TitzerCommit Bot
Ben L. Titzer
authored and
Commit Bot
committed
[wasm] 0-count is out-of-bounds for table.*
The spec wasn't clear (or I misunderstood). As per (WebAssembly/bulk-memory-operations#11), zero-count table operations are also out of bounds. [email protected] [email protected] BUG=v8:7747 Change-Id: Iac689b93a040eb6eb06975bc2ba0facb85d24756 Reviewed-on: https://chromium-review.googlesource.com/c/1436022 Reviewed-by: Michael Starzinger <[email protected]> Commit-Queue: Ben Titzer <[email protected]> Cr-Commit-Position: refs/heads/master@{#59121}
1 parent a1efb41 commit 3a638a5

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

src/wasm/module-instantiate.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,6 @@ bool LoadElemSegmentImpl(Isolate* isolate, Handle<WasmInstanceObject> instance,
14611461
JSToWasmWrapperCache* js_to_wasm_cache,
14621462
const WasmElemSegment& elem_segment, uint32_t dst,
14631463
uint32_t src, size_t count) {
1464-
if (count == 0) return true; // nothing to do.
14651464
if (!IsInBounds(dst, count, table_instance.table_size)) return false;
14661465
if (!IsInBounds(src, count, elem_segment.entries.size())) return false;
14671466

src/wasm/wasm-objects.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,6 @@ bool WasmInstanceObject::CopyTableEntries(Isolate* isolate,
14391439
uint32_t table_index, uint32_t dst,
14401440
uint32_t src, uint32_t count) {
14411441
CHECK_EQ(0, table_index); // TODO(titzer): multiple tables in TableCopy
1442-
if (count == 0) return true; // no-op
14431442
auto max = instance->indirect_function_table_size();
14441443
if (!IsInBounds(dst, count, max)) return false;
14451444
if (!IsInBounds(src, count, max)) return false;

test/mjsunit/wasm/table-copy.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
3030
copy(0, i, kTableSize - i);
3131
copy(i, 0, kTableSize - i);
3232
}
33-
let big = 1000000;
34-
copy(big, 0, 0); // nop
35-
copy(0, big, 0); // nop
3633
})();
3734

3835
function addFunction(builder, k) {
@@ -176,6 +173,13 @@ function assertCall(call, ...elems) {
176173
assertThrows(() => copy(1, 0, kTableSize));
177174
assertThrows(() => copy(0, 1, kTableSize));
178175

176+
{
177+
let big = 1000000;
178+
assertThrows(() => copy(big, 0, 0));
179+
assertThrows(() => copy(0, big, 0));
180+
}
181+
182+
179183
for (let big = 4294967295; big > 1000; big >>>= 1) {
180184
assertThrows(() => copy(big, 0, 1));
181185
assertThrows(() => copy(0, big, 1));
@@ -187,6 +191,7 @@ function assertCall(call, ...elems) {
187191
assertThrows(() => copy(0, big, 1));
188192
assertThrows(() => copy(0, 0, big));
189193
}
194+
190195
})();
191196

192197
(function TestTableCopyShared() {

test/mjsunit/wasm/table-init.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ function assertTable(obj, ...elems) {
5757

5858
assertTable(x.table, null, null, null, null, null);
5959

60-
// 0-count is not oob.
61-
x.init0(0, 0, 0);
62-
assertTable(x.table, null, null, null, null, null);
63-
x.init0(kTableSize+1, 0, 0);
64-
assertTable(x.table, null, null, null, null, null);
65-
x.init0(0, kTableSize+1, 0);
66-
assertTable(x.table, null, null, null, null, null);
67-
6860
// test actual writes.
6961
x.init0(0, 0, 1);
7062
assertTable(x.table, x.f0, null, null, null, null);
@@ -109,6 +101,11 @@ function assertTable(obj, ...elems) {
109101
let x = instance.exports;
110102

111103
assertTable(x.table, null, null, null, null, null);
104+
105+
// 0-count is oob.
106+
assertThrows(() => x.init0(kTableSize+1, 0, 0));
107+
assertThrows(() => x.init0(0, kTableSize+1, 0));
108+
112109
assertThrows(() => x.init0(0, 0, 6));
113110
assertThrows(() => x.init0(0, 1, 5));
114111
assertThrows(() => x.init0(0, 2, 4));

0 commit comments

Comments
 (0)