Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TableFill bounds checking #6621

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3137,21 +3137,16 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
}
auto info = getTableInstanceInfo(curr->table);

auto* table = self()->wasm.getTable(info.name);
Index dest = table->indexType == Type::i64
? destFlow.getSingleValue().geti64()
: destFlow.getSingleValue().geti32();
auto dest = destFlow.getSingleValue().getUnsigned();
Literal value = valueFlow.getSingleValue();
Index size = table->indexType == Type::i64
? sizeFlow.getSingleValue().geti64()
: sizeFlow.getSingleValue().geti32();
auto size = sizeFlow.getSingleValue().getUnsigned();

Index tableSize = info.interface()->tableSize(info.name);
auto tableSize = info.interface()->tableSize(info.name);
if (dest + size > tableSize) {
trap("out of bounds table access");
}

for (Index i = 0; i < size; ++i) {
for (uint64_t i = 0; i < size; i++) {
info.interface()->tableStore(info.name, dest + i, value);
}
return Flow();
Expand Down
32 changes: 32 additions & 0 deletions test/lit/exec/table.fill.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --output=fuzz-exec and should not be edited.

;; RUN: wasm-opt %s -all --fuzz-exec-before -q -o /dev/null 2>&1 | filecheck %s

(module
(type $i32 (func (result i32)))

(table $table 32 32 funcref)

(func $i32 (type $i32) (result i32)
(i32.const 0)
)

;; CHECK: [fuzz-exec] calling fill
;; CHECK-NEXT: [trap out of bounds table access]
(func $fill (export "fill")
;; This fill is out of bounds as the -1 is unsigned. Nothing will be written.
(table.fill $table
(i32.const 1)
(ref.func $i32)
(i32.const -1)
)
)
;; CHECK: [fuzz-exec] calling call
;; CHECK-NEXT: [trap uninitialized table element]
(func $call (export "call") (result i32)
;; Nothing was written, so this traps.
(call_indirect $table (type $i32)
(i32.const 1)
)
)
)
Loading