Debian Codegraph @

internal/integration_test/spectest/v2/testdata/binary.wast

raw
1 (module binary "\00asm\01\00\00\00")
2 (module binary "\00asm" "\01\00\00\00")
3 (module $M1 binary "\00asm\01\00\00\00")
4 (module $M2 binary "\00asm" "\01\00\00\00")
5
6 (assert_malformed (module binary "") "unexpected end")
7 (assert_malformed (module binary "\01") "unexpected end")
8 (assert_malformed (module binary "\00as") "unexpected end")
9 (assert_malformed (module binary "asm\00") "magic header not detected")
10 (assert_malformed (module binary "msa\00") "magic header not detected")
11 (assert_malformed (module binary "msa\00\01\00\00\00") "magic header not detected")
12 (assert_malformed (module binary "msa\00\00\00\00\01") "magic header not detected")
13 (assert_malformed (module binary "asm\01\00\00\00\00") "magic header not detected")
14 (assert_malformed (module binary "wasm\01\00\00\00") "magic header not detected")
15 (assert_malformed (module binary "\7fasm\01\00\00\00") "magic header not detected")
16 (assert_malformed (module binary "\80asm\01\00\00\00") "magic header not detected")
17 (assert_malformed (module binary "\82asm\01\00\00\00") "magic header not detected")
18 (assert_malformed (module binary "\ffasm\01\00\00\00") "magic header not detected")
19
20 ;; 8-byte endian-reversed.
21 (assert_malformed (module binary "\00\00\00\01msa\00") "magic header not detected")
22
23 ;; Middle-endian byte orderings.
24 (assert_malformed (module binary "a\00ms\00\01\00\00") "magic header not detected")
25 (assert_malformed (module binary "sm\00a\00\00\01\00") "magic header not detected")
26
27 ;; Upper-cased.
28 (assert_malformed (module binary "\00ASM\01\00\00\00") "magic header not detected")
29
30 ;; EBCDIC-encoded magic.
31 (assert_malformed (module binary "\00\81\a2\94\01\00\00\00") "magic header not detected")
32
33 ;; Leading UTF-8 BOM.
34 (assert_malformed (module binary "\ef\bb\bf\00asm\01\00\00\00") "magic header not detected")
35
36 ;; Malformed binary version.
37 (assert_malformed (module binary "\00asm") "unexpected end")
38 (assert_malformed (module binary "\00asm\01") "unexpected end")
39 (assert_malformed (module binary "\00asm\01\00\00") "unexpected end")
40 (assert_malformed (module binary "\00asm\00\00\00\00") "unknown binary version")
41 (assert_malformed (module binary "\00asm\0d\00\00\00") "unknown binary version")
42 (assert_malformed (module binary "\00asm\0e\00\00\00") "unknown binary version")
43 (assert_malformed (module binary "\00asm\00\01\00\00") "unknown binary version")
44 (assert_malformed (module binary "\00asm\00\00\01\00") "unknown binary version")
45 (assert_malformed (module binary "\00asm\00\00\00\01") "unknown binary version")
46
47 ;; Invalid section id.
48 (assert_malformed (module binary "\00asm" "\01\00\00\00" "\0e\01\00") "malformed section id")
49 (assert_malformed (module binary "\00asm" "\01\00\00\00" "\7f\01\00") "malformed section id")
50 (assert_malformed (module binary "\00asm" "\01\00\00\00" "\80\01\00\01\01\00") "malformed section id")
51 (assert_malformed (module binary "\00asm" "\01\00\00\00" "\81\01\00\01\01\00") "malformed section id")
52 (assert_malformed (module binary "\00asm" "\01\00\00\00" "\ff\01\00\01\01\00") "malformed section id")
53
54 ;; Function with missing end marker (between two functions)
55 (assert_malformed
56 (module binary
57 "\00asm" "\01\00\00\00"
58 "\01\04\01\60\00\00" ;; Type section: 1 type
59 "\03\03\02\00\00" ;; Function section: 2 functions
60 "\0a\0c\02" ;; Code section: 2 functions
61 ;; function 0
62 "\04\00" ;; Function size and local type count
63 "\41\01" ;; i32.const 1
64 "\1a" ;; drop
65 ;; Missing end marker here
66 ;; function 1
67 "\05\00" ;; Function size and local type count
68 "\41\01" ;; i32.const 1
69 "\1a" ;; drop
70 "\0b" ;; end
71 )
72 "END opcode expected"
73 )
74
75 ;; Function with missing end marker (at EOF)
76 (assert_malformed
77 (module binary
78 "\00asm" "\01\00\00\00"
79 "\01\04\01\60\00\00" ;; Type section: 1 type
80 "\03\02\01\00" ;; Function section: 1 function
81 "\0a\06\01" ;; Code section: 1 function
82 ;; function 0
83 "\04\00" ;; Function size and local type count
84 "\41\01" ;; i32.const 1
85 "\1a" ;; drop
86 ;; Missing end marker here
87 )
88 "unexpected end of section or function"
89 )
90
91 ;; Function with missing end marker (at end of code sections)
92 (assert_malformed
93 (module binary
94 "\00asm" "\01\00\00\00"
95 "\01\04\01\60\00\00" ;; Type section: 1 type
96 "\03\02\01\00" ;; Function section: 1 function
97 "\0a\06\01" ;; Code section: 1 function
98 ;; function 0
99 "\04\00" ;; Function size and local type count
100 "\41\01" ;; i32.const 1
101 "\1a" ;; drop
102 ;; Missing end marker here
103 "\0b\03\01\01\00" ;; Data section
104 )
105 ;; The spec interpreter consumes the `\0b` (data section start) as an
106 ;; END instruction (also happens to be `\0b`) and reports the code section as
107 ;; being larger than declared.
108 "section size mismatch"
109 )
110
111 ;; Init expression with missing end marker
112 (assert_malformed
113 (module binary
114 "\00asm" "\01\00\00\00"
115 "\01\04\01\60\00\00" ;; Type section: 1 type
116 "\03\02\01\00" ;; Function section: 1 function
117 "\06\05\01\7f\00\41\00" ;; Global section: 1 entry with missing end marker
118 ;; Missing end marker here
119 "\0a\04\01\02\00\0b" ;; Code section: 1 function
120 )
121 "illegal opcode"
122 )
123
124 ;; memory.grow reserved byte equal to zero.
125 (assert_malformed
126 (module binary
127 "\00asm" "\01\00\00\00"
128 "\01\04\01\60\00\00" ;; Type section
129 "\03\02\01\00" ;; Function section
130 "\05\03\01\00\00" ;; Memory section
131 "\0a\09\01" ;; Code section
132
133 ;; function 0
134 "\07\00"
135 "\41\00" ;; i32.const 0
136 "\40" ;; memory.grow
137 "\01" ;; memory.grow reserved byte is not equal to zero!
138 "\1a" ;; drop
139 "\0b" ;; end
140 )
141 "zero byte expected"
142 )
143
144 ;; memory.grow reserved byte should not be a "long" LEB128 zero.
145 (assert_malformed
146 (module binary
147 "\00asm" "\01\00\00\00"
148 "\01\04\01\60\00\00" ;; Type section
149 "\03\02\01\00" ;; Function section
150 "\05\03\01\00\00" ;; Memory section
151 "\0a\0a\01" ;; Code section
152
153 ;; function 0
154 "\08\00"
155 "\41\00" ;; i32.const 0
156 "\40" ;; memory.grow
157 "\80\00" ;; memory.grow reserved byte
158 "\1a" ;; drop
159 "\0b" ;; end
160 )
161 "zero byte expected"
162 )
163
164 ;; Same as above for 3, 4, and 5-byte zero encodings.
165 (assert_malformed
166 (module binary
167 "\00asm" "\01\00\00\00"
168 "\01\04\01\60\00\00" ;; Type section
169 "\03\02\01\00" ;; Function section
170 "\05\03\01\00\00" ;; Memory section
171 "\0a\0b\01" ;; Code section
172
173 ;; function 0
174 "\09\00"
175 "\41\00" ;; i32.const 0
176 "\40" ;; memory.grow
177 "\80\80\00" ;; memory.grow reserved byte
178 "\1a" ;; drop
179 "\0b" ;; end
180 )
181 "zero byte expected"
182 )
183
184 (assert_malformed
185 (module binary
186 "\00asm" "\01\00\00\00"
187 "\01\04\01\60\00\00" ;; Type section
188 "\03\02\01\00" ;; Function section
189 "\05\03\01\00\00" ;; Memory section
190 "\0a\0c\01" ;; Code section
191
192 ;; function 0
193 "\0a\00"
194 "\41\00" ;; i32.const 0
195 "\40" ;; memory.grow
196 "\80\80\80\00" ;; memory.grow reserved byte
197 "\1a" ;; drop
198 "\0b" ;; end
199 )
200 "zero byte expected"
201 )
202
203 (assert_malformed
204 (module binary
205 "\00asm" "\01\00\00\00"
206 "\01\04\01\60\00\00" ;; Type section
207 "\03\02\01\00" ;; Function section
208 "\05\03\01\00\00" ;; Memory section
209 "\0a\0d\01" ;; Code section
210
211 ;; function 0
212 "\0b\00"
213 "\41\00" ;; i32.const 0
214 "\40" ;; memory.grow
215 "\80\80\80\80\00" ;; memory.grow reserved byte
216 "\1a" ;; drop
217 "\0b" ;; end
218 )
219 "zero byte expected"
220 )
221
222 ;; memory.size reserved byte equal to zero.
223 (assert_malformed
224 (module binary
225 "\00asm" "\01\00\00\00"
226 "\01\04\01\60\00\00" ;; Type section
227 "\03\02\01\00" ;; Function section
228 "\05\03\01\00\00" ;; Memory section
229 "\0a\07\01" ;; Code section
230
231 ;; function 0
232 "\05\00"
233 "\3f" ;; memory.size
234 "\01" ;; memory.size reserved byte is not equal to zero!
235 "\1a" ;; drop
236 "\0b" ;; end
237 )
238 "zero byte expected"
239 )
240
241 ;; memory.size reserved byte should not be a "long" LEB128 zero.
242 (assert_malformed
243 (module binary
244 "\00asm" "\01\00\00\00"
245 "\01\04\01\60\00\00" ;; Type section
246 "\03\02\01\00" ;; Function section
247 "\05\03\01\00\00" ;; Memory section
248 "\0a\08\01" ;; Code section
249
250 ;; function 0
251 "\06\00"
252 "\3f" ;; memory.size
253 "\80\00" ;; memory.size reserved byte
254 "\1a" ;; drop
255 "\0b" ;; end
256 )
257 "zero byte expected"
258 )
259
260 ;; Same as above for 3, 4, and 5-byte zero encodings.
261 (assert_malformed
262 (module binary
263 "\00asm" "\01\00\00\00"
264 "\01\04\01\60\00\00" ;; Type section
265 "\03\02\01\00" ;; Function section
266 "\05\03\01\00\00" ;; Memory section
267 "\0a\09\01" ;; Code section
268
269 ;; function 0
270 "\07\00"
271 "\3f" ;; memory.size
272 "\80\80\00" ;; memory.size reserved byte
273 "\1a" ;; drop
274 "\0b" ;; end
275 )
276 "zero byte expected"
277 )
278
279 (assert_malformed
280 (module binary
281 "\00asm" "\01\00\00\00"
282 "\01\04\01\60\00\00" ;; Type section
283 "\03\02\01\00" ;; Function section
284 "\05\03\01\00\00" ;; Memory section
285 "\0a\0a\01" ;; Code section
286
287 ;; function 0
288 "\08\00"
289 "\3f" ;; memory.size
290 "\80\80\80\00" ;; memory.size reserved byte
291 "\1a" ;; drop
292 "\0b" ;; end
293 )
294 "zero byte expected"
295 )
296
297 (assert_malformed
298 (module binary
299 "\00asm" "\01\00\00\00"
300 "\01\04\01\60\00\00" ;; Type section
301 "\03\02\01\00" ;; Function section
302 "\05\03\01\00\00" ;; Memory section
303 "\0a\0b\01" ;; Code section
304
305 ;; function 0
306 "\09\00"
307 "\3f" ;; memory.size
308 "\80\80\80\80\00" ;; memory.size reserved byte
309 "\1a" ;; drop
310 "\0b" ;; end
311 )
312 "zero byte expected"
313 )
314
315 ;; Local number is unsigned 32 bit
316 (assert_malformed
317 (module binary
318 "\00asm" "\01\00\00\00"
319 "\01\04\01\60\00\00" ;; Type section
320 "\03\02\01\00" ;; Function section
321 "\0a\0c\01" ;; Code section
322
323 ;; function 0
324 "\0a\02"
325 "\80\80\80\80\10\7f" ;; 0x100000000 i32
326 "\02\7e" ;; 0x00000002 i64
327 "\0b" ;; end
328 )
329 "integer too large"
330 )
331
332 ;; Local number is unsigned 32 bit
333 (assert_malformed
334 (module binary
335 "\00asm" "\01\00\00\00"
336 "\01\04\01\60\00\00" ;; Type section
337 "\03\02\01\00" ;; Function section
338 "\0a\0c\01" ;; Code section
339
340 ;; function 0
341 "\0a\02"
342 "\80\80\80\80\10\7f" ;; 0x100000000 i32
343 "\02\7e" ;; 0x00000002 i64
344 "\0b" ;; end
345 )
346 "integer too large"
347 )
348
349 ;; No more than 2^32-1 locals.
350 (assert_malformed
351 (module binary
352 "\00asm" "\01\00\00\00"
353 "\01\04\01\60\00\00" ;; Type section
354 "\03\02\01\00" ;; Function section
355 "\0a\0c\01" ;; Code section
356
357 ;; function 0
358 "\0a\02"
359 "\ff\ff\ff\ff\0f\7f" ;; 0xFFFFFFFF i32
360 "\02\7e" ;; 0x00000002 i64
361 "\0b" ;; end
362 )
363 "too many locals"
364 )
365
366 (assert_malformed
367 (module binary
368 "\00asm" "\01\00\00\00"
369 "\01\06\01\60\02\7f\7f\00" ;; Type section: (param i32 i32)
370 "\03\02\01\00" ;; Function section
371 "\0a\1c\01" ;; Code section
372
373 ;; function 0
374 "\1a\04"
375 "\80\80\80\80\04\7f" ;; 0x40000000 i32
376 "\80\80\80\80\04\7e" ;; 0x40000000 i64
377 "\80\80\80\80\04\7d" ;; 0x40000000 f32
378 "\80\80\80\80\04\7c" ;; 0x40000000 f64
379 "\0b" ;; end
380 )
381 "too many locals"
382 )
383
384 ;; Local count can be 0.
385 (module binary
386 "\00asm" "\01\00\00\00"
387 "\01\04\01\60\00\00" ;; Type section
388 "\03\02\01\00" ;; Function section
389 "\0a\0a\01" ;; Code section
390
391 ;; function 0
392 "\08\03"
393 "\00\7f" ;; 0 i32
394 "\00\7e" ;; 0 i64
395 "\02\7d" ;; 2 f32
396 "\0b" ;; end
397 )
398
399 ;; Function section has non-zero count, but code section is absent.
400 (assert_malformed
401 (module binary
402 "\00asm" "\01\00\00\00"
403 "\01\04\01\60\00\00" ;; Type section
404 "\03\03\02\00\00" ;; Function section with 2 functions
405 )
406 "function and code section have inconsistent lengths"
407 )
408
409 ;; Code section has non-zero count, but function section is absent.
410 (assert_malformed
411 (module binary
412 "\00asm" "\01\00\00\00"
413 "\0a\04\01\02\00\0b" ;; Code section with 1 empty function
414 )
415 "function and code section have inconsistent lengths"
416 )
417
418 ;; Function section count > code section count
419 (assert_malformed
420 (module binary
421 "\00asm" "\01\00\00\00"
422 "\01\04\01\60\00\00" ;; Type section
423 "\03\03\02\00\00" ;; Function section with 2 functions
424 "\0a\04\01\02\00\0b" ;; Code section with 1 empty function
425 )
426 "function and code section have inconsistent lengths"
427 )
428
429 ;; Function section count < code section count
430 (assert_malformed
431 (module binary
432 "\00asm" "\01\00\00\00"
433 "\01\04\01\60\00\00" ;; Type section
434 "\03\02\01\00" ;; Function section with 1 function
435 "\0a\07\02\02\00\0b\02\00\0b" ;; Code section with 2 empty functions
436 )
437 "function and code section have inconsistent lengths"
438 )
439
440 ;; Function section has zero count, and code section is absent.
441 (module binary
442 "\00asm" "\01\00\00\00"
443 "\03\01\00" ;; Function section with 0 functions
444 )
445
446 ;; Code section has zero count, and function section is absent.
447 (module binary
448 "\00asm" "\01\00\00\00"
449 "\0a\01\00" ;; Code section with 0 functions
450 )
451
452 ;; Fewer passive segments than data count
453 (assert_malformed
454 (module binary
455 "\00asm" "\01\00\00\00"
456 "\0c\01\03" ;; Data count section with value 3
457 "\0b\05\02" ;; Data section with two entries
458 "\01\00" ;; Passive data section
459 "\01\00" ;; Passive data section
460 )
461 "data count and data section have inconsistent lengths"
462 )
463
464 ;; More passive segments than data count
465 (assert_malformed
466 (module binary
467 "\00asm" "\01\00\00\00"
468 "\0c\01\01" ;; Data count section with value 1
469 "\0b\05\02" ;; Data section with two entries
470 "\01\00" ;; Passive data section
471 "\01\00" ;; Passive data section
472 )
473 "data count and data section have inconsistent lengths"
474 )
475
476 ;; Non-zero data count section without data section
477 (assert_malformed
478 (module binary
479 "\00asm" "\01\00\00\00"
480 "\05\03\01\00\01" ;; Memory section with one entry
481 "\0c\01\01" ;; Data count section with value 1
482 )
483 "data count and data section have inconsistent lengths"
484 )
485
486 ;; Zero data count section without data section
487 (module binary
488 "\00asm" "\01\00\00\00"
489 "\0c\01\00" ;; Data count section with value 0
490 )
491
492 ;; memory.init requires a data count section
493 (assert_malformed
494 (module binary
495 "\00asm" "\01\00\00\00"
496
497 "\01\04\01\60\00\00" ;; Type section
498 "\03\02\01\00" ;; Function section
499 "\05\03\01\00\00" ;; Memory section
500 "\0a\0e\01" ;; Code section
501
502 ;; function 0
503 "\0c\00"
504 "\41\00" ;; zero args
505 "\41\00"
506 "\41\00"
507 "\fc\08\00\00" ;; memory.init
508 "\0b"
509
510 "\0b\03\01\01\00" ;; Data section
511 ) ;; end
512 "data count section required"
513 )
514
515 ;; data.drop requires a data count section
516 (assert_malformed
517 (module binary
518 "\00asm" "\01\00\00\00"
519
520 "\01\04\01\60\00\00" ;; Type section
521 "\03\02\01\00" ;; Function section
522 "\05\03\01\00\00" ;; Memory section
523 "\0a\07\01" ;; Code section
524
525 ;; function 0
526 "\05\00"
527 "\fc\09\00" ;; data.drop
528 "\0b"
529
530 "\0b\03\01\01\00" ;; Data section
531 ) ;; end
532 "data count section required"
533 )
534
535 ;; passive element segment containing illegal opcode
536 (assert_malformed
537 (module binary
538 "\00asm" "\01\00\00\00"
539
540 "\01\04\01\60\00\00" ;; Type section
541
542 "\03\02\01\00" ;; Function section
543
544 "\04\04\01" ;; Table section with 1 entry
545 "\70\00\00" ;; no max, minimum 0, funcref
546
547 "\05\03\01\00\00" ;; Memory section
548
549 "\09\07\01" ;; Element section with one segment
550 "\05\70" ;; Passive, funcref
551 "\01" ;; 1 element
552 "\f3\00\0b" ;; bad opcode, index 0, end
553
554 "\0a\04\01" ;; Code section
555
556 ;; function 0
557 "\02\00"
558 "\0b" ;; end
559 )
560 "illegal opcode"
561 )
562
563 ;; passive element segment containing type other than funcref
564 (assert_malformed
565 (module binary
566 "\00asm" "\01\00\00\00"
567
568 "\01\04\01\60\00\00" ;; Type section
569
570 "\03\02\01\00" ;; Function section
571
572 "\04\04\01" ;; Table section with 1 entry
573 "\70\00\00" ;; no max, minimum 0, funcref
574
575 "\05\03\01\00\00" ;; Memory section
576
577 "\09\07\01" ;; Element section with one segment
578 "\05\7f" ;; Passive, i32
579 "\01" ;; 1 element
580 "\d2\00\0b" ;; ref.func, index 0, end
581
582 "\0a\04\01" ;; Code section
583
584 ;; function 0
585 "\02\00"
586 "\0b" ;; end
587 )
588 "malformed reference type"
589 )
590
591 ;; passive element segment containing opcode ref.func
592 (module binary
593 "\00asm" "\01\00\00\00"
594
595 "\01\04\01\60\00\00" ;; Type section
596
597 "\03\02\01\00" ;; Function section
598
599 "\04\04\01" ;; Table section with 1 entry
600 "\70\00\00" ;; no max, minimum 0, funcref
601
602 "\05\03\01\00\00" ;; Memory section
603
604 "\09\07\01" ;; Element section with one segment
605 "\05\70" ;; Passive, funcref
606 "\01" ;; 1 element
607 "\d2\00\0b" ;; ref.func, index 0, end
608
609 "\0a\04\01" ;; Code section
610
611 ;; function 0
612 "\02\00"
613 "\0b" ;; end
614 )
615
616 ;; passive element segment containing opcode ref.null
617 (module binary
618 "\00asm" "\01\00\00\00"
619
620 "\01\04\01\60\00\00" ;; Type section
621
622 "\03\02\01\00" ;; Function section
623
624 "\04\04\01" ;; Table section with 1 entry
625 "\70\00\00" ;; no max, minimum 0, funcref
626
627 "\05\03\01\00\00" ;; Memory section
628
629 "\09\07\01" ;; Element section with one segment
630 "\05\70" ;; Passive, funcref
631 "\01" ;; 1 element
632 "\d0\70\0b" ;; ref.null, end
633
634 "\0a\04\01" ;; Code section
635
636 ;; function 0
637 "\02\00"
638 "\0b" ;; end
639 )
640
641
642 ;; Type count can be zero
643 (module binary
644 "\00asm" "\01\00\00\00"
645 "\01\01\00" ;; type count can be zero
646 )
647
648 ;; 2 type declared, 1 given
649 (assert_malformed
650 (module binary
651 "\00asm" "\01\00\00\00"
652 "\01\07\02" ;; type section with inconsistent count (2 declared, 1 given)
653 "\60\00\00" ;; 1st type
654 ;; "\60\00\00" ;; 2nd type (missed)
655 )
656 "length out of bounds"
657 )
658
659 ;; 1 type declared, 2 given
660 (assert_malformed
661 (module binary
662 "\00asm" "\01\00\00\00"
663 "\01\07\01" ;; type section with inconsistent count (1 declared, 2 given)
664 "\60\00\00" ;; 1st type
665 "\60\00\00" ;; 2nd type (redundant)
666 )
667 "section size mismatch"
668 )
669
670 ;; Import count can be zero
671 (module binary
672 "\00asm" "\01\00\00\00"
673 "\01\05\01" ;; type section
674 "\60\01\7f\00" ;; type 0
675 "\02\01\00" ;; import count can be zero
676 )
677
678 ;; Malformed import kind
679 (assert_malformed
680 (module binary
681 "\00asm" "\01\00\00\00"
682 "\02\04\01" ;; import section with single entry
683 "\00" ;; string length 0
684 "\00" ;; string length 0
685 "\04" ;; malformed import kind
686 )
687 "malformed import kind"
688 )
689 (assert_malformed
690 (module binary
691 "\00asm" "\01\00\00\00"
692 "\02\05\01" ;; import section with single entry
693 "\00" ;; string length 0
694 "\00" ;; string length 0
695 "\04" ;; malformed import kind
696 "\00" ;; dummy byte
697 )
698 "malformed import kind"
699 )
700 (assert_malformed
701 (module binary
702 "\00asm" "\01\00\00\00"
703 "\02\04\01" ;; import section with single entry
704 "\00" ;; string length 0
705 "\00" ;; string length 0
706 "\05" ;; malformed import kind
707 )
708 "malformed import kind"
709 )
710 (assert_malformed
711 (module binary
712 "\00asm" "\01\00\00\00"
713 "\02\05\01" ;; import section with single entry
714 "\00" ;; string length 0
715 "\00" ;; string length 0
716 "\05" ;; malformed import kind
717 "\00" ;; dummy byte
718 )
719 "malformed import kind"
720 )
721 (assert_malformed
722 (module binary
723 "\00asm" "\01\00\00\00"
724 "\02\04\01" ;; import section with single entry
725 "\00" ;; string length 0
726 "\00" ;; string length 0
727 "\80" ;; malformed import kind
728 )
729 "malformed import kind"
730 )
731 (assert_malformed
732 (module binary
733 "\00asm" "\01\00\00\00"
734 "\02\05\01" ;; import section with single entry
735 "\00" ;; string length 0
736 "\00" ;; string length 0
737 "\80" ;; malformed import kind
738 "\00" ;; dummy byte
739 )
740 "malformed import kind"
741 )
742
743 ;; 2 import declared, 1 given
744 (assert_malformed
745 (module binary
746 "\00asm" "\01\00\00\00"
747 "\01\05\01" ;; type section
748 "\60\01\7f\00" ;; type 0
749 "\02\16\02" ;; import section with inconsistent count (2 declared, 1 given)
750 ;; 1st import
751 "\08" ;; string length
752 "\73\70\65\63\74\65\73\74" ;; spectest
753 "\09" ;; string length
754 "\70\72\69\6e\74\5f\69\33\32" ;; print_i32
755 "\00\00" ;; import kind, import signature index
756 ;; 2nd import
757 ;; (missed)
758 )
759 "unexpected end of section or function"
760 )
761
762 ;; 1 import declared, 2 given
763 (assert_malformed
764 (module binary
765 "\00asm" "\01\00\00\00"
766 "\01\09\02" ;; type section
767 "\60\01\7f\00" ;; type 0
768 "\60\01\7d\00" ;; type 1
769 "\02\2b\01" ;; import section with inconsistent count (1 declared, 2 given)
770 ;; 1st import
771 "\08" ;; string length
772 "\73\70\65\63\74\65\73\74" ;; spectest
773 "\09" ;; string length
774 "\70\72\69\6e\74\5f\69\33\32" ;; print_i32
775 "\00\00" ;; import kind, import signature index
776 ;; 2nd import
777 ;; (redundant)
778 "\08" ;; string length
779 "\73\70\65\63\74\65\73\74" ;; spectest
780 "\09" ;; string length
781 "\70\72\69\6e\74\5f\66\33\32" ;; print_f32
782 "\00\01" ;; import kind, import signature index
783 )
784 "section size mismatch"
785 )
786
787 ;; Table count can be zero
788 (module binary
789 "\00asm" "\01\00\00\00"
790 "\04\01\00" ;; table count can be zero
791 )
792
793 ;; 1 table declared, 0 given
794 (assert_malformed
795 (module binary
796 "\00asm" "\01\00\00\00"
797 "\04\01\01" ;; table section with inconsistent count (1 declared, 0 given)
798 ;; "\70\01\00\00" ;; table entity
799 )
800 "unexpected end of section or function"
801 )
802
803 ;; Malformed table limits flag
804 (assert_malformed
805 (module binary
806 "\00asm" "\01\00\00\00"
807 "\04\03\01" ;; table section with one entry
808 "\70" ;; anyfunc
809 "\02" ;; malformed table limits flag
810 )
811 "integer too large"
812 )
813 (assert_malformed
814 (module binary
815 "\00asm" "\01\00\00\00"
816 "\04\04\01" ;; table section with one entry
817 "\70" ;; anyfunc
818 "\08" ;; malformed table limits flag
819 "\00" ;; dummy byte
820 )
821 "integer too large"
822 )
823 (assert_malformed
824 (module binary
825 "\00asm" "\01\00\00\00"
826 "\04\06\01" ;; table section with one entry
827 "\70" ;; anyfunc
828 "\81\00" ;; malformed table limits flag as LEB128
829 "\00\00" ;; dummy bytes
830 )
831 "integer representation too long"
832 )
833
834 ;; Memory count can be zero
835 (module binary
836 "\00asm" "\01\00\00\00"
837 "\05\01\00" ;; memory count can be zero
838 )
839
840 ;; 1 memory declared, 0 given
841 (assert_malformed
842 (module binary
843 "\00asm" "\01\00\00\00"
844 "\05\01\01" ;; memory section with inconsistent count (1 declared, 0 given)
845 ;; "\00\00" ;; memory 0 (missed)
846 )
847 "unexpected end of section or function"
848 )
849
850 ;; Malformed memory limits flag
851 (assert_malformed
852 (module binary
853 "\00asm" "\01\00\00\00"
854 "\05\02\01" ;; memory section with one entry
855 "\02" ;; malformed memory limits flag
856 )
857 "integer too large"
858 )
859 (assert_malformed
860 (module binary
861 "\00asm" "\01\00\00\00"
862 "\05\03\01" ;; memory section with one entry
863 "\10" ;; malformed memory limits flag
864 "\00" ;; dummy byte
865 )
866 "integer too large"
867 )
868 (assert_malformed
869 (module binary
870 "\00asm" "\01\00\00\00"
871 "\05\05\01" ;; memory section with one entry
872 "\81\00" ;; malformed memory limits flag as LEB128
873 "\00\00" ;; dummy bytes
874 )
875 "integer representation too long"
876 )
877 (assert_malformed
878 (module binary
879 "\00asm" "\01\00\00\00"
880 "\05\05\01" ;; memory section with one entry
881 "\81\01" ;; malformed memory limits flag as LEB128
882 "\00\00" ;; dummy bytes
883 )
884 "integer representation too long"
885 )
886
887 ;; Global count can be zero
888 (module binary
889 "\00asm" "\01\00\00\00"
890 "\06\01\00" ;; global count can be zero
891 )
892
893 ;; 2 global declared, 1 given
894 (assert_malformed
895 (module binary
896 "\00asm" "\01\00\00\00"
897 "\06\06\02" ;; global section with inconsistent count (2 declared, 1 given)
898 "\7f\00\41\00\0b" ;; global 0
899 ;; "\7f\00\41\00\0b" ;; global 1 (missed)
900 )
901 "unexpected end of section or function"
902 )
903
904 ;; 1 global declared, 2 given
905 (assert_malformed
906 (module binary
907 "\00asm" "\01\00\00\00"
908 "\06\0b\01" ;; global section with inconsistent count (1 declared, 2 given)
909 "\7f\00\41\00\0b" ;; global 0
910 "\7f\00\41\00\0b" ;; global 1 (redundant)
911 )
912 "section size mismatch"
913 )
914
915 ;; Export count can be 0
916 (module binary
917 "\00asm" "\01\00\00\00"
918 "\01\04\01" ;; type section
919 "\60\00\00" ;; type 0
920 "\03\03\02\00\00" ;; func section
921 "\07\01\00" ;; export count can be zero
922 "\0a\07\02" ;; code section
923 "\02\00\0b" ;; function body 0
924 "\02\00\0b" ;; function body 1
925 )
926
927 ;; 2 export declared, 1 given
928 (assert_malformed
929 (module binary
930 "\00asm" "\01\00\00\00"
931 "\01\04\01" ;; type section
932 "\60\00\00" ;; type 0
933 "\03\03\02\00\00" ;; func section
934 "\07\06\02" ;; export section with inconsistent count (2 declared, 1 given)
935 "\02" ;; export 0
936 "\66\31" ;; export name
937 "\00\00" ;; export kind, export func index
938 ;; "\02" ;; export 1 (missed)
939 ;; "\66\32" ;; export name
940 ;; "\00\01" ;; export kind, export func index
941 "\0a\07\02" ;; code section
942 "\02\00\0b" ;; function body 0
943 "\02\00\0b" ;; function body 1
944 )
945 "length out of bounds"
946 )
947
948 ;; 1 export declared, 2 given
949 (assert_malformed
950 (module binary
951 "\00asm" "\01\00\00\00"
952 "\01\04\01" ;; type section
953 "\60\00\00" ;; type 0
954 "\03\03\02\00\00" ;; func section
955 "\07\0b\01" ;; export section with inconsistent count (1 declared, 2 given)
956 "\02" ;; export 0
957 "\66\31" ;; export name
958 "\00\00" ;; export kind, export func index
959 "\02" ;; export 1 (redundant)
960 "\66\32" ;; export name
961 "\00\01" ;; export kind, export func index
962 "\0a\07\02" ;; code section
963 "\02\00\0b" ;; function body 0
964 "\02\00\0b" ;; function body 1
965 )
966 "section size mismatch"
967 )
968
969 ;; elem segment count can be zero
970 (module binary
971 "\00asm" "\01\00\00\00"
972 "\01\04\01" ;; type section
973 "\60\00\00" ;; type 0
974 "\03\02\01\00" ;; func section
975 "\04\04\01" ;; table section
976 "\70\00\01" ;; table 0
977 "\09\01\00" ;; elem segment count can be zero
978 "\0a\04\01" ;; code section
979 "\02\00\0b" ;; function body
980 )
981
982 ;; 2 elem segment declared, 1 given
983 (assert_malformed
984 (module binary
985 "\00asm" "\01\00\00\00"
986 "\01\04\01" ;; type section
987 "\60\00\00" ;; type 0
988 "\03\02\01\00" ;; func section
989 "\04\04\01" ;; table section
990 "\70\00\01" ;; table 0
991 "\09\07\02" ;; elem with inconsistent segment count (2 declared, 1 given)
992 "\00\41\00\0b\01\00" ;; elem 0
993 ;; "\00\41\00\0b\01\00" ;; elem 1 (missed)
994 )
995 "unexpected end"
996 )
997
998 ;; 2 elem segment declared, 1.5 given
999 (assert_malformed
1000 (module binary
1001 "\00asm" "\01\00\00\00"
1002 "\01\04\01" ;; type section
1003 "\60\00\00" ;; type 0
1004 "\03\02\01\00" ;; func section
1005 "\04\04\01" ;; table section
1006 "\70\00\01" ;; table 0
1007 "\09\0a\02" ;; elem with inconsistent segment count (2 declared, 1 given)
1008 "\00\41\00\0b\01\00" ;; elem 0
1009 "\00\41\00" ;; elem 1 (partial)
1010 ;; "\0b\01\00" ;; elem 1 (missing part)
1011 )
1012 "unexpected end"
1013 )
1014
1015 ;; 1 elem segment declared, 2 given
1016 (assert_malformed
1017 (module binary
1018 "\00asm" "\01\00\00\00"
1019 "\01\04\01" ;; type section
1020 "\60\00\00" ;; type 0
1021 "\03\02\01\00" ;; func section
1022 "\04\04\01" ;; table section
1023 "\70\00\01" ;; table 0
1024 "\09\0d\01" ;; elem with inconsistent segment count (1 declared, 2 given)
1025 "\00\41\00\0b\01\00" ;; elem 0
1026 "\00\41\00\0b\01\00" ;; elem 1 (redundant)
1027 "\0a\04\01" ;; code section
1028 "\02\00\0b" ;; function body
1029 )
1030 "section size mismatch"
1031 )
1032
1033 ;; data segment count can be zero
1034 (module binary
1035 "\00asm" "\01\00\00\00"
1036 "\05\03\01" ;; memory section
1037 "\00\01" ;; memory 0
1038 "\0b\01\00" ;; data segment count can be zero
1039 )
1040
1041 ;; 2 data segment declared, 1 given
1042 (assert_malformed
1043 (module binary
1044 "\00asm" "\01\00\00\00"
1045 "\05\03\01" ;; memory section
1046 "\00\01" ;; memory 0
1047 "\0b\07\02" ;; data with inconsistent segment count (2 declared, 1 given)
1048 "\00\41\00\0b\01\61" ;; data 0
1049 ;; "\00\41\01\0b\01\62" ;; data 1 (missed)
1050 )
1051 "unexpected end of section or function"
1052 )
1053
1054 ;; 1 data segment declared, 2 given
1055 (assert_malformed
1056 (module binary
1057 "\00asm" "\01\00\00\00"
1058 "\05\03\01" ;; memory section
1059 "\00\01" ;; memory 0
1060 "\0b\0d\01" ;; data with inconsistent segment count (1 declared, 2 given)
1061 "\00\41\00\0b\01\61" ;; data 0
1062 "\00\41\01\0b\01\62" ;; data 1 (redundant)
1063 )
1064 "section size mismatch"
1065 )
1066
1067 ;; data segment has 7 bytes declared, but 6 bytes given
1068 (assert_malformed
1069 (module binary
1070 "\00asm" "\01\00\00\00"
1071 "\05\03\01" ;; memory section
1072 "\00\01" ;; memory 0
1073 "\0b\0c\01" ;; data section
1074 "\00\41\03\0b" ;; data segment 0
1075 "\07" ;; data segment size with inconsistent lengths (7 declared, 6 given)
1076 "\61\62\63\64\65\66" ;; 6 bytes given
1077 )
1078 "unexpected end of section or function"
1079 )
1080
1081 ;; data segment has 5 bytes declared, but 6 bytes given
1082 (assert_malformed
1083 (module binary
1084 "\00asm" "\01\00\00\00"
1085 "\05\03\01" ;; memory section
1086 "\00\01" ;; memory 0
1087 "\0b\0c\01" ;; data section
1088 "\00\41\00\0b" ;; data segment 0
1089 "\05" ;; data segment size with inconsistent lengths (5 declared, 6 given)
1090 "\61\62\63\64\65\66" ;; 6 bytes given
1091 )
1092 "section size mismatch"
1093 )
1094
1095 ;; br_table target count can be zero
1096 (module binary
1097 "\00asm" "\01\00\00\00"
1098 "\01\04\01" ;; type section
1099 "\60\00\00" ;; type 0
1100 "\03\02\01\00" ;; func section
1101 "\0a\11\01" ;; code section
1102 "\0f\00" ;; func 0
1103 "\02\40" ;; block 0
1104 "\41\01" ;; condition of if 0
1105 "\04\40" ;; if 0
1106 "\41\01" ;; index of br_table element
1107 "\0e\00" ;; br_table target count can be zero
1108 "\02" ;; break depth for default
1109 "\0b\0b\0b" ;; end
1110 )
1111
1112 ;; 1 br_table target declared, 2 given
1113 (assert_malformed
1114 (module binary
1115 "\00asm" "\01\00\00\00"
1116 "\01\25\0c" ;; type section
1117 "\60\00\00" ;; type 0
1118 "\60\00\00" ;; type 1
1119 "\60\00\00" ;; type 2
1120 "\60\00\00" ;; type 3
1121 "\60\00\00" ;; type 4
1122 "\60\00\00" ;; type 5
1123 "\60\00\00" ;; type 6
1124 "\60\00\00" ;; type 7
1125 "\60\00\00" ;; type 8
1126 "\60\00\00" ;; type 9
1127 "\60\00\00" ;; type 10
1128 "\60\00\00" ;; type 11
1129 "\03\02\01\00" ;; func section
1130 "\0a\13\01" ;; code section
1131 "\11\00" ;; func 0
1132 "\02\40" ;; block 0
1133 "\41\01" ;; condition of if 0
1134 "\04\40" ;; if 0
1135 "\41\01" ;; index of br_table element
1136 "\0e\01" ;; br_table with inconsistent target count (1 declared, 2 given)
1137 "\00" ;; break depth 0
1138 "\01" ;; break depth 1
1139 "\02" ;; break depth for default, interpreted as a block
1140 "\0b" ;; end, interpreted as type 11 for the block
1141 "\0b\0b" ;; end
1142 )
1143 "unexpected end"
1144 )
1145
1146 ;; Start section
1147 (module binary
1148 "\00asm" "\01\00\00\00"
1149 "\01\04\01\60\00\00" ;; Type section
1150 "\03\02\01\00" ;; Function section
1151 "\08\01\00" ;; Start section: function 0
1152
1153 "\0a\04\01" ;; Code section
1154 ;; function 0
1155 "\02\00"
1156 "\0b" ;; end
1157 )
1158
1159 ;; Multiple start sections
1160 (assert_malformed
1161 (module binary
1162 "\00asm" "\01\00\00\00"
1163 "\01\04\01\60\00\00" ;; Type section
1164 "\03\02\01\00" ;; Function section
1165 "\08\01\00" ;; Start section: function 0
1166 "\08\01\00" ;; Start section: function 0
1167
1168 "\0a\04\01" ;; Code section
1169 ;; function 0
1170 "\02\00"
1171 "\0b" ;; end
1172 )
1173 "unexpected content after last section"
1174 )
1175
1176 ;; Multiple function sections
1177 (assert_malformed
1178 (module binary
1179 "\00asm" "\01\00\00\00"
1180 "\01\04\01\60\00\00" ;; Type section
1181 "\03\02\01\00" ;; Function section with 1 function
1182 "\03\02\01\00" ;; Function section with 1 function
1183 "\0a\07\02\02\00\0b\02\00\0b" ;; Code section with 2 empty functions
1184 )
1185 "unexpected content after last section"
1186 )
1187
1188 ;; Multiple code sections
1189 (assert_malformed
1190 (module binary
1191 "\00asm" "\01\00\00\00"
1192 "\01\04\01\60\00\00" ;; Type section
1193 "\03\03\02\00\00" ;; Function section with 2 functions
1194 "\0a\04\01\02\00\0b" ;; Code section with 1 empty function
1195 "\0a\04\01\02\00\0b" ;; Code section with 1 empty function
1196 )
1197 "unexpected content after last section"
1198 )
1199
1200 ;; Multiple data count sections
1201 (assert_malformed
1202 (module binary
1203 "\00asm" "\01\00\00\00"
1204 "\0c\01\01" ;; Data count section with value "1"
1205 "\0c\01\01" ;; Data count section with value "1"
1206 )
1207 "unexpected content after last section"
1208 )
1209
1210 ;; Multiple data sections
1211 (assert_malformed
1212 (module binary
1213 "\00asm" "\01\00\00\00"
1214 "\0b\01\00" ;; Data section with zero entries
1215 "\0b\01\00" ;; Data section with zero entries
1216 )
1217 "unexpected content after last section"
1218 )
1219
1220 ;; Multiple global sections
1221 (assert_malformed
1222 (module binary
1223 "\00asm" "\01\00\00\00"
1224 "\06\01\00" ;; Global section with zero entries
1225 "\06\01\00" ;; Global section with zero entries
1226 )
1227 "unexpected content after last section"
1228 )
1229
1230 ;; Multiple export sections
1231 (assert_malformed
1232 (module binary
1233 "\00asm" "\01\00\00\00"
1234 "\07\01\00" ;; Export section with zero entries
1235 "\07\01\00" ;; Export section with zero entries
1236 )
1237 "unexpected content after last section"
1238 )
1239
1240 ;; Multiple table sections
1241 (assert_malformed
1242 (module binary
1243 "\00asm" "\01\00\00\00"
1244 "\04\01\00" ;; Table section with zero entries
1245 "\04\01\00" ;; Table section with zero entries
1246 )
1247 "unexpected content after last section"
1248 )
1249
1250 ;; Multiple element sections
1251 (assert_malformed
1252 (module binary
1253 "\00asm" "\01\00\00\00"
1254 "\09\01\00" ;; Element section with zero entries
1255 "\09\01\00" ;; Element section with zero entries
1256 )
1257 "unexpected content after last section"
1258 )
1259
1260 ;; Multiple import sections
1261 (assert_malformed
1262 (module binary
1263 "\00asm" "\01\00\00\00"
1264 "\02\01\00" ;; Import section with zero entries
1265 "\02\01\00" ;; Import section with zero entries
1266 )
1267 "unexpected content after last section"
1268 )
1269
1270 ;; Multiple type sections
1271 (assert_malformed
1272 (module binary
1273 "\00asm" "\01\00\00\00"
1274 "\01\01\00" ;; Type section with zero entries
1275 "\01\01\00" ;; Type section with zero entries
1276 )
1277 "unexpected content after last section"
1278 )
1279
1280 ;; Multiple memory sections
1281 (assert_malformed
1282 (module binary
1283 "\00asm" "\01\00\00\00"
1284 "\05\01\00" ;; Memory section with zero entries
1285 "\05\01\00" ;; Memory section with zero entries
1286 )
1287 "unexpected content after last section"
1288 )
1289
1290 ;; Type section out of order
1291 (assert_malformed
1292 (module binary
1293 "\00asm" "\01\00\00\00"
1294 "\02\01\00" ;; Import section with zero entries
1295 "\01\01\00" ;; Type section with zero entries
1296 )
1297 "unexpected content after last section"
1298 )
1299
1300 ;; Import section out of order
1301 (assert_malformed
1302 (module binary
1303 "\00asm" "\01\00\00\00"
1304 "\03\01\00" ;; Function section with zero entries
1305 "\02\01\00" ;; Import section with zero entries
1306 )
1307 "unexpected content after last section"
1308 )
1309
1310 ;; Function section out of order
1311 (assert_malformed
1312 (module binary
1313 "\00asm" "\01\00\00\00"
1314 "\04\01\00" ;; Table section with zero entries
1315 "\03\01\00" ;; Function section with zero entries
1316 )
1317 "unexpected content after last section"
1318 )
1319
1320 ;; Table section out of order
1321 (assert_malformed
1322 (module binary
1323 "\00asm" "\01\00\00\00"
1324 "\05\01\00" ;; Memory section with zero entries
1325 "\04\01\00" ;; Table section with zero entries
1326 )
1327 "unexpected content after last section"
1328 )
1329
1330 ;; Memory section out of order
1331 (assert_malformed
1332 (module binary
1333 "\00asm" "\01\00\00\00"
1334 "\06\01\00" ;; Global section with zero entries
1335 "\05\01\00" ;; Memory section with zero entries
1336 )
1337 "unexpected content after last section"
1338 )
1339
1340 ;; Global section out of order
1341 (assert_malformed
1342 (module binary
1343 "\00asm" "\01\00\00\00"
1344 "\07\01\00" ;; Export section with zero entries
1345 "\06\01\00" ;; Global section with zero entries
1346 )
1347 "unexpected content after last section"
1348 )
1349
1350 ;; Export section out of order
1351 (assert_malformed
1352 (module binary
1353 "\00asm" "\01\00\00\00"
1354 "\01\04\01\60\00\00" ;; Type section
1355 "\03\02\01\00" ;; Function section
1356 "\08\01\00" ;; Start section: function 0
1357 "\07\01\00" ;; Export section with zero entries
1358 )
1359 "unexpected content after last section"
1360 )
1361
1362 ;; Start section out of order
1363 (assert_malformed
1364 (module binary
1365 "\00asm" "\01\00\00\00"
1366 "\01\04\01\60\00\00" ;; Type section
1367 "\03\02\01\00" ;; Function section
1368 "\09\01\00" ;; Element section with zero entries
1369 "\08\01\00" ;; Start section: function 0
1370 )
1371 "unexpected content after last section"
1372 )
1373
1374 ;; Element section out of order
1375 (assert_malformed
1376 (module binary
1377 "\00asm" "\01\00\00\00"
1378 "\0c\01\01" ;; Data count section with value "1"
1379 "\09\01\00" ;; Element section with zero entries
1380 )
1381 "unexpected content after last section"
1382 )
1383
1384 ;; Data count section out of order
1385 (assert_malformed
1386 (module binary
1387 "\00asm" "\01\00\00\00"
1388 "\0a\01\00" ;; Code section with zero entries
1389 "\0c\01\01" ;; Data count section with value "1"
1390 )
1391 "unexpected content after last section"
1392 )
1393
1394 ;; Code section out of order
1395 (assert_malformed
1396 (module binary
1397 "\00asm" "\01\00\00\00"
1398 "\0b\01\00" ;; Data section with zero entries
1399 "\0a\01\00" ;; Code section with zero entries
1400 )
1401 "unexpected content after last section"
1402 )
1403