Skip to content

Commit efa2158

Browse files
authored
Test array.new_data and array.new_elem with dropped segments (WebAssembly#1849)
Also test that the instructions trap when the offset and size overflow back to zero, with and without the segments having been dropped.
1 parent d1bf45a commit efa2158

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/core/gc/array.wast

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@
158158
(array.new_data $vec $d (i32.const 1) (i32.const 3))
159159
)
160160

161+
(func $new-overflow (export "new-overflow") (result (ref $vec))
162+
(array.new_data $vec $d (i32.const 0x8000_0000) (i32.const 0x8000_0000))
163+
)
164+
161165
(func $get_u (param $i i32) (param $v (ref $vec)) (result i32)
162166
(array.get_u $vec (local.get $v) (local.get $i))
163167
)
@@ -189,6 +193,10 @@
189193
(func (export "len") (result i32)
190194
(call $len (call $new))
191195
)
196+
197+
(func (export "drop_segs")
198+
(data.drop $d)
199+
)
192200
)
193201

194202
(assert_return (invoke "new") (ref.array))
@@ -198,10 +206,16 @@
198206
(assert_return (invoke "set_get" (i32.const 1) (i32.const 7)) (i32.const 7))
199207
(assert_return (invoke "len") (i32.const 3))
200208

209+
(assert_trap (invoke "new-overflow") "out of bounds memory access")
201210
(assert_trap (invoke "get_u" (i32.const 10)) "out of bounds array access")
202211
(assert_trap (invoke "get_s" (i32.const 10)) "out of bounds array access")
203212
(assert_trap (invoke "set_get" (i32.const 10) (i32.const 7)) "out of bounds array access")
204213

214+
(assert_return (invoke "drop_segs"))
215+
216+
(assert_trap (invoke "new") "out of bounds memory access")
217+
(assert_trap (invoke "new-overflow") "out of bounds memory access")
218+
205219
(module
206220
(type $bvec (array i8))
207221
(type $vec (array (ref $bvec)))
@@ -218,6 +232,10 @@
218232
(array.new_elem $vec $e (i32.const 0) (i32.const 2))
219233
)
220234

235+
(func $new-overflow (export "new-overflow") (result (ref $vec))
236+
(array.new_elem $vec $e (i32.const 0x8000_0000) (i32.const 0x8000_0000))
237+
)
238+
221239
(func $sub1 (result (ref $nvec))
222240
(array.new_elem $nvec $e (i32.const 0) (i32.const 2))
223241
)
@@ -249,6 +267,10 @@
249267
(func (export "len") (result i32)
250268
(call $len (call $new))
251269
)
270+
271+
(func (export "drop_segs")
272+
(elem.drop $e)
273+
)
252274
)
253275

254276
(assert_return (invoke "new") (ref.array))
@@ -258,9 +280,15 @@
258280
(assert_return (invoke "set_get" (i32.const 0) (i32.const 1) (i32.const 1)) (i32.const 2))
259281
(assert_return (invoke "len") (i32.const 2))
260282

283+
(assert_trap (invoke "new-overflow") "out of bounds table access")
261284
(assert_trap (invoke "get" (i32.const 10) (i32.const 0)) "out of bounds array access")
262285
(assert_trap (invoke "set_get" (i32.const 10) (i32.const 0) (i32.const 0)) "out of bounds array access")
263286

287+
(assert_return (invoke "drop_segs"))
288+
289+
(assert_trap (invoke "new") "out of bounds table access")
290+
(assert_trap (invoke "new-overflow") "out of bounds table access")
291+
264292
(assert_invalid
265293
(module
266294
(type $a (array i64))

0 commit comments

Comments
 (0)