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

[GC] Fix trapping on array.new_data of dropped segments of offset > 0 #7124

Merged
merged 5 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4023,7 +4023,7 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
const auto& seg = *wasm.getDataSegment(curr->segment);
auto elemBytes = element.getByteSize();
auto end = offset + size * elemBytes;
if ((size != 0ull && droppedDataSegments.count(curr->segment)) ||
if ((offset + size > 0 && droppedDataSegments.count(curr->segment)) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we should check for overflow as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

end > seg.data.size()) {
trap("out of bounds segment access in array.new_data");
}
Expand Down
21 changes: 21 additions & 0 deletions test/lit/exec/array.wast
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

(elem $passive $func)

(data $data "a")

;; CHECK: [fuzz-exec] calling func
;; CHECK-NEXT: [fuzz-exec] note result: func => 1
(func $func (export "func") (result i32)
Expand Down Expand Up @@ -98,6 +100,21 @@
(i32.const 0)
)
)

;; CHECK: [fuzz-exec] calling drop_array.new_data
;; CHECK-NEXT: [trap out of bounds segment access in array.new_data]
(func $drop_array.new_data (export "drop_array.new_data")
;; Dropping the data segment causes the next instruction to trap, even though
;; the size there is 0, because the offset is > 0.
(data.drop $data)
(drop
(array.new_data $array $data
(i32.const 1)
(i32.const 0)
)
)
)

)
;; CHECK: [fuzz-exec] calling func
;; CHECK-NEXT: [fuzz-exec] note result: func => 1
Expand All @@ -115,6 +132,10 @@
;; CHECK: [fuzz-exec] calling init_active_in_bounds

;; CHECK: [fuzz-exec] calling init_passive

;; CHECK: [fuzz-exec] calling drop_array.new_data
;; CHECK-NEXT: [trap out of bounds segment access in array.new_data]
;; CHECK-NEXT: [fuzz-exec] comparing drop_array.new_data
;; CHECK-NEXT: [fuzz-exec] comparing func
;; CHECK-NEXT: [fuzz-exec] comparing init_active
;; CHECK-NEXT: [fuzz-exec] comparing init_active_in_bounds
Expand Down