Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

[test] Update generated tests for OOBs and dropping changes #131

Merged
merged 1 commit into from
Nov 22, 2019
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
10 changes: 8 additions & 2 deletions test/core/memory_copy.wast
Original file line number Diff line number Diff line change
Expand Up @@ -4869,7 +4869,7 @@
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x20000) (i32.const 0x7000) (i32.const 0))))
(invoke "test")
(assert_trap (invoke "test") "out of bounds")

(module
(memory 1 1)
Expand All @@ -4881,14 +4881,20 @@
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x9000) (i32.const 0x20000) (i32.const 0))))
(invoke "test")
(assert_trap (invoke "test") "out of bounds")

(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x10000) (i32.const 0x10000) (i32.const 0))))
(invoke "test")

(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x20000) (i32.const 0x20000) (i32.const 0))))
(assert_trap (invoke "test") "out of bounds")

(module
(memory 1 1)
(func (export "test")
Expand Down
2 changes: 1 addition & 1 deletion test/core/memory_fill.wast
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@

(func (export "test")
(memory.fill (i32.const 0x20000) (i32.const 0x55) (i32.const 0))))
(invoke "test")
(assert_trap (invoke "test") "out of bounds")

(module
(memory 1 1)
Expand Down
17 changes: 12 additions & 5 deletions test/core/memory_init.wast
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,22 @@
(func (export "test")
(data.drop 0)
(data.drop 0)))
(assert_trap (invoke "test") "data segment dropped")
(invoke "test")

(module
(memory 1)
(data "\37")
(func (export "test")
(data.drop 0)
(memory.init 0 (i32.const 1234) (i32.const 1) (i32.const 1))))
(assert_trap (invoke "test") "data segment dropped")
(assert_trap (invoke "test") "out of bounds")

(module
(memory 1)
(data (i32.const 0) "\37")
(func (export "test")
(memory.init 0 (i32.const 1234) (i32.const 1) (i32.const 1))))
(assert_trap (invoke "test") "data segment dropped")
(assert_trap (invoke "test") "out of bounds")

(assert_invalid
(module
Expand Down Expand Up @@ -270,7 +270,7 @@
(data "\37")
(func (export "test")
(memory.init 0 (i32.const 1234) (i32.const 4) (i32.const 0))))
(invoke "test")
(assert_trap (invoke "test") "out of bounds")

(module
(memory 1)
Expand All @@ -284,7 +284,7 @@
(data "\37")
(func (export "test")
(memory.init 0 (i32.const 0x10001) (i32.const 0) (i32.const 0))))
(invoke "test")
(assert_trap (invoke "test") "out of bounds")

(module
(memory 1)
Expand All @@ -300,6 +300,13 @@
(memory.init 0 (i32.const 0x10000) (i32.const 1) (i32.const 0))))
(invoke "test")

(module
(memory 1)
(data "\37")
(func (export "test")
(memory.init 0 (i32.const 0x10001) (i32.const 4) (i32.const 0))))
(assert_trap (invoke "test") "out of bounds")

(assert_invalid
(module
(memory 1)
Expand Down
28 changes: 26 additions & 2 deletions test/core/table_copy.wast
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@
(table.copy (i32.const 31) (i32.const 15) (i32.const 0))
))

(invoke "test")
(assert_trap (invoke "test") "out of bounds")

(module
(table 30 30 funcref)
Expand Down Expand Up @@ -681,7 +681,7 @@
(table.copy (i32.const 15) (i32.const 31) (i32.const 0))
))

(invoke "test")
(assert_trap (invoke "test") "out of bounds")

(module
(table 30 30 funcref)
Expand All @@ -707,6 +707,30 @@

(invoke "test")

(module
(table 30 30 funcref)
(elem (i32.const 2) 3 1 4 1)
(elem funcref
(ref.func 2) (ref.func 7) (ref.func 1) (ref.func 8))
(elem (i32.const 12) 7 5 2 3 6)
(elem funcref
(ref.func 5) (ref.func 9) (ref.func 2) (ref.func 7) (ref.func 6))
(func (result i32) (i32.const 0))
(func (result i32) (i32.const 1))
(func (result i32) (i32.const 2))
(func (result i32) (i32.const 3))
(func (result i32) (i32.const 4))
(func (result i32) (i32.const 5))
(func (result i32) (i32.const 6))
(func (result i32) (i32.const 7))
(func (result i32) (i32.const 8))
(func (result i32) (i32.const 9))
(func (export "test")
(table.copy (i32.const 31) (i32.const 31) (i32.const 0))
))

(assert_trap (invoke "test") "out of bounds")

(module
(type (func (result i32)))
(table 32 64 funcref)
Expand Down
35 changes: 29 additions & 6 deletions test/core/table_init.wast
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
(func (export "test")
(elem.drop 2)
))
(assert_trap (invoke "test") "element segment dropped")
(invoke "test")

(module
(table 30 30 funcref)
Expand All @@ -262,7 +262,7 @@
(func (export "test")
(table.init 2 (i32.const 12) (i32.const 1) (i32.const 1))
))
(assert_trap (invoke "test") "element segment dropped")
(assert_trap (invoke "test") "out of bounds")

(module
(table 30 30 funcref)
Expand Down Expand Up @@ -308,7 +308,7 @@
(func (export "test")
(elem.drop 1)
(elem.drop 1)))
(assert_trap (invoke "test") "element segment dropped")
(invoke "test")

(module
(table 30 30 funcref)
Expand All @@ -331,7 +331,7 @@
(func (export "test")
(elem.drop 1)
(table.init 1 (i32.const 12) (i32.const 1) (i32.const 1))))
(assert_trap (invoke "test") "element segment dropped")
(assert_trap (invoke "test") "out of bounds")

(module
(table 30 30 funcref)
Expand Down Expand Up @@ -446,7 +446,7 @@
(func (export "test")
(table.init 1 (i32.const 12) (i32.const 5) (i32.const 0))
))
(invoke "test")
(assert_trap (invoke "test") "out of bounds")

(module
(table 30 30 funcref)
Expand Down Expand Up @@ -492,7 +492,7 @@
(func (export "test")
(table.init 1 (i32.const 31) (i32.const 2) (i32.const 0))
))
(invoke "test")
(assert_trap (invoke "test") "out of bounds")

(module
(table 30 30 funcref)
Expand All @@ -517,6 +517,29 @@
))
(invoke "test")

(module
(table 30 30 funcref)
(elem (i32.const 2) 3 1 4 1)
(elem funcref
(ref.func 2) (ref.func 7) (ref.func 1) (ref.func 8))
(elem (i32.const 12) 7 5 2 3 6)
(elem funcref
(ref.func 5) (ref.func 9) (ref.func 2) (ref.func 7) (ref.func 6))
(func (result i32) (i32.const 0))
(func (result i32) (i32.const 1))
(func (result i32) (i32.const 2))
(func (result i32) (i32.const 3))
(func (result i32) (i32.const 4))
(func (result i32) (i32.const 5))
(func (result i32) (i32.const 6))
(func (result i32) (i32.const 7))
(func (result i32) (i32.const 8))
(func (result i32) (i32.const 9))
(func (export "test")
(table.init 1 (i32.const 31) (i32.const 5) (i32.const 0))
))
(assert_trap (invoke "test") "out of bounds")

(assert_invalid
(module
(table 10 funcref)
Expand Down
17 changes: 13 additions & 4 deletions test/meta/generate_memory_copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@ print(
(invoke "test")
`);

// Zero len with dest offset out-of-bounds past the end of memory is allowed
// Zero len with dest offset out-of-bounds past the end of memory is not allowed
print(
`(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x20000) (i32.const 0x7000) (i32.const 0))))
(invoke "test")
(assert_trap (invoke "test") "out of bounds")
`);

// Zero len with src offset out-of-bounds at the end of memory is allowed
Expand All @@ -298,13 +298,13 @@ print(
(invoke "test")
`);

// Zero len with src offset out-of-bounds past the end of memory is allowed
// Zero len with src offset out-of-bounds past the end of memory is not allowed
print(
`(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x9000) (i32.const 0x20000) (i32.const 0))))
(invoke "test")
(assert_trap (invoke "test") "out of bounds")
`);

// Zero len with both dest and src offsets out-of-bounds at the end of memory is allowed
Expand All @@ -316,6 +316,15 @@ print(
(invoke "test")
`);

// Zero len with both dest and src offsets out-of-bounds past the end of memory is not allowed
print(
`(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x20000) (i32.const 0x20000) (i32.const 0))))
(assert_trap (invoke "test") "out of bounds")
`);

// 100 random fills followed by 100 random copies, in a single-page buffer,
// followed by verification of the (now heavily mashed-around) buffer.
print(
Expand Down
6 changes: 3 additions & 3 deletions test/meta/generate_memory_fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ print(
(invoke "test")
`);

// Zero len with offset out-of-bounds past the end of memory is allowed
// Zero len with offset out-of-bounds past the end of memory is not allowed
print(
`(module
${PREAMBLE}
(func (export "test")
(memory.fill (i32.const 0x20000) (i32.const 0x55) (i32.const 0))))
(invoke "test")
(assert_trap (invoke "test") "out of bounds")
`);

// Very large range
Expand Down Expand Up @@ -136,7 +136,7 @@ function mem_fill(min, max, shared, backup, write=backup*2) {
(func (export "run") (param $offs i32) (param $val i32) (param $len i32)
(memory.fill (local.get $offs) (local.get $val) (local.get $len))))
`);
// A fill past the end should throw *and* have filled all the way up to the end
// A fill past the end should throw *and* not have performed a partial fill
let offs = min*PAGESIZE - backup;
let val = 37;
print(
Expand Down
24 changes: 17 additions & 7 deletions test/meta/generate_memory_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ print(
(func (export "test")
(data.drop 0)
(data.drop 0)))
(assert_trap (invoke "test") "data segment dropped")
(invoke "test")
`);

// drop, then init
Expand All @@ -95,7 +95,7 @@ print(
(func (export "test")
(data.drop 0)
(memory.init 0 (i32.const 1234) (i32.const 1) (i32.const 1))))
(assert_trap (invoke "test") "data segment dropped")
(assert_trap (invoke "test") "out of bounds")
`);

// init with data seg ix indicating an active segment
Expand All @@ -105,7 +105,7 @@ print(
(data (i32.const 0) "\\37")
(func (export "test")
(memory.init 0 (i32.const 1234) (i32.const 1) (i32.const 1))))
(assert_trap (invoke "test") "data segment dropped")
(assert_trap (invoke "test") "out of bounds")
`);

// init with no memory
Expand Down Expand Up @@ -164,13 +164,13 @@ print(
(assert_trap (invoke "test") "out of bounds")
`);

// init: seg ix is valid passive, src offset past the end, zero len is always valid
// init: seg ix is valid passive, src offset past the end, zero len is invalid
print(
`(module
${PREAMBLE}
(func (export "test")
(memory.init 0 (i32.const 1234) (i32.const 4) (i32.const 0))))
(invoke "test")
(assert_trap (invoke "test") "out of bounds")
`);

// init: seg ix is valid passive, zero len, src offset at the end
Expand All @@ -182,13 +182,13 @@ print(
(invoke "test")
`);

// init: seg ix is valid passive, dst offset past the end, zero len is always valid
// init: seg ix is valid passive, dst offset past the end, zero len is invalid
print(
`(module
${PREAMBLE}
(func (export "test")
(memory.init 0 (i32.const 0x10001) (i32.const 0) (i32.const 0))))
(invoke "test")
(assert_trap (invoke "test") "out of bounds")
`);

// init: seg ix is valid passive, zero len, but dst offset at the end
Expand All @@ -209,6 +209,16 @@ print(
(invoke "test")
`);

// init: seg ix is valid passive, src and dst offset past the end, zero len is
// invalid
print(
`(module
${PREAMBLE}
(func (export "test")
(memory.init 0 (i32.const 0x10001) (i32.const 4) (i32.const 0))))
(assert_trap (invoke "test") "out of bounds")
`);

// invalid argument types. TODO: can add anyfunc etc here.
{
const tys = ['i32', 'f32', 'i64', 'f64'];
Expand Down
Loading