Skip to content

Commit 438b85d

Browse files
committed
[test] Update generated tests for OOBs and dropping changes
1 parent 6086773 commit 438b85d

10 files changed

+134
-48
lines changed

test/core/memory_copy.wast

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4869,7 +4869,7 @@
48694869
(memory 1 1)
48704870
(func (export "test")
48714871
(memory.copy (i32.const 0x20000) (i32.const 0x7000) (i32.const 0))))
4872-
(invoke "test")
4872+
(assert_trap (invoke "test") "out of bounds")
48734873

48744874
(module
48754875
(memory 1 1)
@@ -4881,14 +4881,20 @@
48814881
(memory 1 1)
48824882
(func (export "test")
48834883
(memory.copy (i32.const 0x9000) (i32.const 0x20000) (i32.const 0))))
4884-
(invoke "test")
4884+
(assert_trap (invoke "test") "out of bounds")
48854885

48864886
(module
48874887
(memory 1 1)
48884888
(func (export "test")
48894889
(memory.copy (i32.const 0x10000) (i32.const 0x10000) (i32.const 0))))
48904890
(invoke "test")
48914891

4892+
(module
4893+
(memory 1 1)
4894+
(func (export "test")
4895+
(memory.copy (i32.const 0x20000) (i32.const 0x20000) (i32.const 0))))
4896+
(assert_trap (invoke "test") "out of bounds")
4897+
48924898
(module
48934899
(memory 1 1)
48944900
(func (export "test")

test/core/memory_fill.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114

115115
(func (export "test")
116116
(memory.fill (i32.const 0x20000) (i32.const 0x55) (i32.const 0))))
117-
(invoke "test")
117+
(assert_trap (invoke "test") "out of bounds")
118118

119119
(module
120120
(memory 1 1)

test/core/memory_init.wast

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,22 +205,22 @@
205205
(func (export "test")
206206
(data.drop 0)
207207
(data.drop 0)))
208-
(assert_trap (invoke "test") "data segment dropped")
208+
(invoke "test")
209209

210210
(module
211211
(memory 1)
212212
(data "\37")
213213
(func (export "test")
214214
(data.drop 0)
215215
(memory.init 0 (i32.const 1234) (i32.const 1) (i32.const 1))))
216-
(assert_trap (invoke "test") "data segment dropped")
216+
(assert_trap (invoke "test") "out of bounds")
217217

218218
(module
219219
(memory 1)
220220
(data (i32.const 0) "\37")
221221
(func (export "test")
222222
(memory.init 0 (i32.const 1234) (i32.const 1) (i32.const 1))))
223-
(assert_trap (invoke "test") "data segment dropped")
223+
(assert_trap (invoke "test") "out of bounds")
224224

225225
(assert_invalid
226226
(module
@@ -270,7 +270,7 @@
270270
(data "\37")
271271
(func (export "test")
272272
(memory.init 0 (i32.const 1234) (i32.const 4) (i32.const 0))))
273-
(invoke "test")
273+
(assert_trap (invoke "test") "out of bounds")
274274

275275
(module
276276
(memory 1)
@@ -284,7 +284,7 @@
284284
(data "\37")
285285
(func (export "test")
286286
(memory.init 0 (i32.const 0x10001) (i32.const 0) (i32.const 0))))
287-
(invoke "test")
287+
(assert_trap (invoke "test") "out of bounds")
288288

289289
(module
290290
(memory 1)
@@ -300,6 +300,13 @@
300300
(memory.init 0 (i32.const 0x10000) (i32.const 1) (i32.const 0))))
301301
(invoke "test")
302302

303+
(module
304+
(memory 1)
305+
(data "\37")
306+
(func (export "test")
307+
(memory.init 0 (i32.const 0x10001) (i32.const 4) (i32.const 0))))
308+
(assert_trap (invoke "test") "out of bounds")
309+
303310
(assert_invalid
304311
(module
305312
(memory 1)

test/core/table_copy.wast

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@
633633
(table.copy (i32.const 31) (i32.const 15) (i32.const 0))
634634
))
635635

636-
(invoke "test")
636+
(assert_trap (invoke "test") "out of bounds")
637637

638638
(module
639639
(table 30 30 funcref)
@@ -681,7 +681,7 @@
681681
(table.copy (i32.const 15) (i32.const 31) (i32.const 0))
682682
))
683683

684-
(invoke "test")
684+
(assert_trap (invoke "test") "out of bounds")
685685

686686
(module
687687
(table 30 30 funcref)
@@ -707,6 +707,30 @@
707707

708708
(invoke "test")
709709

710+
(module
711+
(table 30 30 funcref)
712+
(elem (i32.const 2) 3 1 4 1)
713+
(elem funcref
714+
(ref.func 2) (ref.func 7) (ref.func 1) (ref.func 8))
715+
(elem (i32.const 12) 7 5 2 3 6)
716+
(elem funcref
717+
(ref.func 5) (ref.func 9) (ref.func 2) (ref.func 7) (ref.func 6))
718+
(func (result i32) (i32.const 0))
719+
(func (result i32) (i32.const 1))
720+
(func (result i32) (i32.const 2))
721+
(func (result i32) (i32.const 3))
722+
(func (result i32) (i32.const 4))
723+
(func (result i32) (i32.const 5))
724+
(func (result i32) (i32.const 6))
725+
(func (result i32) (i32.const 7))
726+
(func (result i32) (i32.const 8))
727+
(func (result i32) (i32.const 9))
728+
(func (export "test")
729+
(table.copy (i32.const 31) (i32.const 31) (i32.const 0))
730+
))
731+
732+
(assert_trap (invoke "test") "out of bounds")
733+
710734
(module
711735
(type (func (result i32)))
712736
(table 32 64 funcref)

test/core/table_init.wast

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
(func (export "test")
240240
(elem.drop 2)
241241
))
242-
(assert_trap (invoke "test") "element segment dropped")
242+
(invoke "test")
243243

244244
(module
245245
(table 30 30 funcref)
@@ -262,7 +262,7 @@
262262
(func (export "test")
263263
(table.init 2 (i32.const 12) (i32.const 1) (i32.const 1))
264264
))
265-
(assert_trap (invoke "test") "element segment dropped")
265+
(assert_trap (invoke "test") "out of bounds")
266266

267267
(module
268268
(table 30 30 funcref)
@@ -308,7 +308,7 @@
308308
(func (export "test")
309309
(elem.drop 1)
310310
(elem.drop 1)))
311-
(assert_trap (invoke "test") "element segment dropped")
311+
(invoke "test")
312312

313313
(module
314314
(table 30 30 funcref)
@@ -331,7 +331,7 @@
331331
(func (export "test")
332332
(elem.drop 1)
333333
(table.init 1 (i32.const 12) (i32.const 1) (i32.const 1))))
334-
(assert_trap (invoke "test") "element segment dropped")
334+
(assert_trap (invoke "test") "out of bounds")
335335

336336
(module
337337
(table 30 30 funcref)
@@ -446,7 +446,7 @@
446446
(func (export "test")
447447
(table.init 1 (i32.const 12) (i32.const 5) (i32.const 0))
448448
))
449-
(invoke "test")
449+
(assert_trap (invoke "test") "out of bounds")
450450

451451
(module
452452
(table 30 30 funcref)
@@ -492,7 +492,7 @@
492492
(func (export "test")
493493
(table.init 1 (i32.const 31) (i32.const 2) (i32.const 0))
494494
))
495-
(invoke "test")
495+
(assert_trap (invoke "test") "out of bounds")
496496

497497
(module
498498
(table 30 30 funcref)
@@ -517,6 +517,29 @@
517517
))
518518
(invoke "test")
519519

520+
(module
521+
(table 30 30 funcref)
522+
(elem (i32.const 2) 3 1 4 1)
523+
(elem funcref
524+
(ref.func 2) (ref.func 7) (ref.func 1) (ref.func 8))
525+
(elem (i32.const 12) 7 5 2 3 6)
526+
(elem funcref
527+
(ref.func 5) (ref.func 9) (ref.func 2) (ref.func 7) (ref.func 6))
528+
(func (result i32) (i32.const 0))
529+
(func (result i32) (i32.const 1))
530+
(func (result i32) (i32.const 2))
531+
(func (result i32) (i32.const 3))
532+
(func (result i32) (i32.const 4))
533+
(func (result i32) (i32.const 5))
534+
(func (result i32) (i32.const 6))
535+
(func (result i32) (i32.const 7))
536+
(func (result i32) (i32.const 8))
537+
(func (result i32) (i32.const 9))
538+
(func (export "test")
539+
(table.init 1 (i32.const 31) (i32.const 5) (i32.const 0))
540+
))
541+
(assert_trap (invoke "test") "out of bounds")
542+
520543
(assert_invalid
521544
(module
522545
(table 10 funcref)

test/meta/generate_memory_copy.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,13 @@ print(
280280
(invoke "test")
281281
`);
282282

283-
// Zero len with dest offset out-of-bounds past the end of memory is allowed
283+
// Zero len with dest offset out-of-bounds past the end of memory is not allowed
284284
print(
285285
`(module
286286
(memory 1 1)
287287
(func (export "test")
288288
(memory.copy (i32.const 0x20000) (i32.const 0x7000) (i32.const 0))))
289-
(invoke "test")
289+
(assert_trap (invoke "test") "out of bounds")
290290
`);
291291

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

301-
// Zero len with src offset out-of-bounds past the end of memory is allowed
301+
// Zero len with src offset out-of-bounds past the end of memory is not allowed
302302
print(
303303
`(module
304304
(memory 1 1)
305305
(func (export "test")
306306
(memory.copy (i32.const 0x9000) (i32.const 0x20000) (i32.const 0))))
307-
(invoke "test")
307+
(assert_trap (invoke "test") "out of bounds")
308308
`);
309309

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

319+
// Zero len with both dest and src offsets out-of-bounds past the end of memory is not allowed
320+
print(
321+
`(module
322+
(memory 1 1)
323+
(func (export "test")
324+
(memory.copy (i32.const 0x20000) (i32.const 0x20000) (i32.const 0))))
325+
(assert_trap (invoke "test") "out of bounds")
326+
`);
327+
319328
// 100 random fills followed by 100 random copies, in a single-page buffer,
320329
// followed by verification of the (now heavily mashed-around) buffer.
321330
print(

test/meta/generate_memory_fill.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ print(
5656
(invoke "test")
5757
`);
5858

59-
// Zero len with offset out-of-bounds past the end of memory is allowed
59+
// Zero len with offset out-of-bounds past the end of memory is not allowed
6060
print(
6161
`(module
6262
${PREAMBLE}
6363
(func (export "test")
6464
(memory.fill (i32.const 0x20000) (i32.const 0x55) (i32.const 0))))
65-
(invoke "test")
65+
(assert_trap (invoke "test") "out of bounds")
6666
`);
6767

6868
// Very large range
@@ -136,7 +136,7 @@ function mem_fill(min, max, shared, backup, write=backup*2) {
136136
(func (export "run") (param $offs i32) (param $val i32) (param $len i32)
137137
(memory.fill (local.get $offs) (local.get $val) (local.get $len))))
138138
`);
139-
// A fill past the end should throw *and* have filled all the way up to the end
139+
// A fill past the end should throw *and* not have performed a partial fill
140140
let offs = min*PAGESIZE - backup;
141141
let val = 37;
142142
print(

test/meta/generate_memory_init.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ print(
8585
(func (export "test")
8686
(data.drop 0)
8787
(data.drop 0)))
88-
(assert_trap (invoke "test") "data segment dropped")
88+
(invoke "test")
8989
`);
9090

9191
// drop, then init
@@ -95,7 +95,7 @@ print(
9595
(func (export "test")
9696
(data.drop 0)
9797
(memory.init 0 (i32.const 1234) (i32.const 1) (i32.const 1))))
98-
(assert_trap (invoke "test") "data segment dropped")
98+
(assert_trap (invoke "test") "out of bounds")
9999
`);
100100

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

111111
// init with no memory
@@ -164,13 +164,13 @@ print(
164164
(assert_trap (invoke "test") "out of bounds")
165165
`);
166166

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

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

185-
// init: seg ix is valid passive, dst offset past the end, zero len is always valid
185+
// init: seg ix is valid passive, dst offset past the end, zero len is invalid
186186
print(
187187
`(module
188188
${PREAMBLE}
189189
(func (export "test")
190190
(memory.init 0 (i32.const 0x10001) (i32.const 0) (i32.const 0))))
191-
(invoke "test")
191+
(assert_trap (invoke "test") "out of bounds")
192192
`);
193193

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

212+
// init: seg ix is valid passive, src and dst offset past the end, zero len is
213+
// invalid
214+
print(
215+
`(module
216+
${PREAMBLE}
217+
(func (export "test")
218+
(memory.init 0 (i32.const 0x10001) (i32.const 4) (i32.const 0))))
219+
(assert_trap (invoke "test") "out of bounds")
220+
`);
221+
212222
// invalid argument types. TODO: can add anyfunc etc here.
213223
{
214224
const tys = ['i32', 'f32', 'i64', 'f64'];

0 commit comments

Comments
 (0)