-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not allow partial segment initialization for tables and memories
- Loading branch information
Showing
3 changed files
with
100 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/misc_testsuite/bulk-memory-operations/partial-init-memory-segment.wast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(module $m | ||
(memory (export "mem") 1) | ||
|
||
(func (export "load") (param i32) (result i32) | ||
local.get 0 | ||
i32.load8_u)) | ||
|
||
(register "m" $m) | ||
|
||
(assert_trap | ||
(module | ||
(memory (import "m" "mem") 1) | ||
|
||
;; This is in bounds, and should get written to the memory. | ||
(data (i32.const 0) "abc") | ||
|
||
;; Partially out of bounds. None of these bytes should get written, and | ||
;; instantiation should trap. | ||
(data (i32.const 65530) "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") | ||
) | ||
"out of bounds" | ||
) | ||
|
||
;; The first data segment got written. | ||
(assert_return (invoke $m "load" (i32.const 0)) (i32.const 97)) | ||
(assert_return (invoke $m "load" (i32.const 1)) (i32.const 98)) | ||
(assert_return (invoke $m "load" (i32.const 2)) (i32.const 99)) | ||
|
||
;; The second did not get partially written. | ||
(assert_return (invoke $m "load" (i32.const 65530)) (i32.const 0)) | ||
(assert_return (invoke $m "load" (i32.const 65531)) (i32.const 0)) | ||
(assert_return (invoke $m "load" (i32.const 65532)) (i32.const 0)) | ||
(assert_return (invoke $m "load" (i32.const 65533)) (i32.const 0)) | ||
(assert_return (invoke $m "load" (i32.const 65534)) (i32.const 0)) | ||
(assert_return (invoke $m "load" (i32.const 65535)) (i32.const 0)) |
35 changes: 35 additions & 0 deletions
35
tests/misc_testsuite/bulk-memory-operations/partial-init-table-segment.wast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(module $m | ||
(table (export "table") funcref (elem $zero $zero $zero $zero $zero $zero $zero $zero $zero $zero)) | ||
|
||
(func $zero (result i32) | ||
(i32.const 0)) | ||
|
||
(func (export "indirect-call") (param i32) (result i32) | ||
local.get 0 | ||
call_indirect (result i32))) | ||
|
||
(register "m" $m) | ||
|
||
(assert_trap | ||
(module | ||
(table (import "m" "table") 10 funcref) | ||
|
||
(func $one (result i32) | ||
(i32.const 1)) | ||
|
||
;; An in-bounds segment that should get initialized in the table. | ||
(elem (i32.const 7) $one) | ||
|
||
;; Part of this segment is out of bounds, so none of its elements should be | ||
;; initialized into the table, and it should trap. | ||
(elem (i32.const 9) $one $one $one) | ||
) | ||
"out of bounds" | ||
) | ||
|
||
;; The first `$one` segment *was* initialized OK. | ||
(assert_return (invoke "indirect-call" (i32.const 7)) (i32.const 1)) | ||
|
||
;; The second `$one` segment is partially out of bounds, and therefore none of | ||
;; its elements were written into the table. | ||
(assert_return (invoke "indirect-call" (i32.const 9)) (i32.const 0)) |