-
Notifications
You must be signed in to change notification settings - Fork 57
/
binary.wast
1401 lines (1251 loc) · 46 KB
/
binary.wast
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(module binary "\00asm\01\00\00\00")
(module binary "\00asm" "\01\00\00\00")
(module $M1 binary "\00asm\01\00\00\00")
(module $M2 binary "\00asm" "\01\00\00\00")
(assert_malformed (module binary "") "unexpected end")
(assert_malformed (module binary "\01") "unexpected end")
(assert_malformed (module binary "\00as") "unexpected end")
(assert_malformed (module binary "asm\00") "magic header not detected")
(assert_malformed (module binary "msa\00") "magic header not detected")
(assert_malformed (module binary "msa\00\01\00\00\00") "magic header not detected")
(assert_malformed (module binary "msa\00\00\00\00\01") "magic header not detected")
(assert_malformed (module binary "asm\01\00\00\00\00") "magic header not detected")
(assert_malformed (module binary "wasm\01\00\00\00") "magic header not detected")
(assert_malformed (module binary "\7fasm\01\00\00\00") "magic header not detected")
(assert_malformed (module binary "\80asm\01\00\00\00") "magic header not detected")
(assert_malformed (module binary "\82asm\01\00\00\00") "magic header not detected")
(assert_malformed (module binary "\ffasm\01\00\00\00") "magic header not detected")
;; 8-byte endian-reversed.
(assert_malformed (module binary "\00\00\00\01msa\00") "magic header not detected")
;; Middle-endian byte orderings.
(assert_malformed (module binary "a\00ms\00\01\00\00") "magic header not detected")
(assert_malformed (module binary "sm\00a\00\00\01\00") "magic header not detected")
;; Upper-cased.
(assert_malformed (module binary "\00ASM\01\00\00\00") "magic header not detected")
;; EBCDIC-encoded magic.
(assert_malformed (module binary "\00\81\a2\94\01\00\00\00") "magic header not detected")
;; Leading UTF-8 BOM.
(assert_malformed (module binary "\ef\bb\bf\00asm\01\00\00\00") "magic header not detected")
;; Malformed binary version.
(assert_malformed (module binary "\00asm") "unexpected end")
(assert_malformed (module binary "\00asm\01") "unexpected end")
(assert_malformed (module binary "\00asm\01\00\00") "unexpected end")
(assert_malformed (module binary "\00asm\00\00\00\00") "unknown binary version")
(assert_malformed (module binary "\00asm\0d\00\00\00") "unknown binary version")
(assert_malformed (module binary "\00asm\0e\00\00\00") "unknown binary version")
(assert_malformed (module binary "\00asm\00\01\00\00") "unknown binary version")
(assert_malformed (module binary "\00asm\00\00\01\00") "unknown binary version")
(assert_malformed (module binary "\00asm\00\00\00\01") "unknown binary version")
;; Invalid section id.
(assert_malformed (module binary "\00asm" "\01\00\00\00" "\0e\01\00") "malformed section id")
(assert_malformed (module binary "\00asm" "\01\00\00\00" "\7f\01\00") "malformed section id")
(assert_malformed (module binary "\00asm" "\01\00\00\00" "\80\01\00\01\01\00") "malformed section id")
(assert_malformed (module binary "\00asm" "\01\00\00\00" "\81\01\00\01\01\00") "malformed section id")
(assert_malformed (module binary "\00asm" "\01\00\00\00" "\ff\01\00\01\01\00") "malformed section id")
;; Function with missing end marker (between two functions)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section: 1 type
"\03\03\02\00\00" ;; Function section: 2 functions
"\0a\0c\02" ;; Code section: 2 functions
;; function 0
"\04\00" ;; Function size and local type count
"\41\01" ;; i32.const 1
"\1a" ;; drop
;; Missing end marker here
;; function 1
"\05\00" ;; Function size and local type count
"\41\01" ;; i32.const 1
"\1a" ;; drop
"\0b" ;; end
)
"END opcode expected"
)
;; Function with missing end marker (at EOF)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section: 1 type
"\03\02\01\00" ;; Function section: 1 function
"\0a\06\01" ;; Code section: 1 function
;; function 0
"\04\00" ;; Function size and local type count
"\41\01" ;; i32.const 1
"\1a" ;; drop
;; Missing end marker here
)
"unexpected end of section or function"
)
;; Function with missing end marker (at end of code sections)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section: 1 type
"\03\02\01\00" ;; Function section: 1 function
"\0a\06\01" ;; Code section: 1 function
;; function 0
"\04\00" ;; Function size and local type count
"\41\01" ;; i32.const 1
"\1a" ;; drop
;; Missing end marker here
"\0b\03\01\01\00" ;; Data section
)
;; The spec interpreter consumes the `\0b` (data section start) as an
;; END instruction (also happens to be `\0b`) and reports the code section as
;; being larger than declared.
"section size mismatch"
)
;; Init expression with missing end marker
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section: 1 type
"\03\02\01\00" ;; Function section: 1 function
"\06\05\01\7f\00\41\00" ;; Global section: 1 entry with missing end marker
;; Missing end marker here
"\0a\04\01\02\00\0b" ;; Code section: 1 function
)
"illegal opcode"
)
;; memory.grow reserved byte equal to zero.
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\05\03\01\00\00" ;; Memory section
"\0a\09\01" ;; Code section
;; function 0
"\07\00"
"\41\00" ;; i32.const 0
"\40" ;; memory.grow
"\01" ;; memory.grow reserved byte is not equal to zero!
"\1a" ;; drop
"\0b" ;; end
)
"zero byte expected"
)
;; memory.grow reserved byte should not be a "long" LEB128 zero.
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\05\03\01\00\00" ;; Memory section
"\0a\0a\01" ;; Code section
;; function 0
"\08\00"
"\41\00" ;; i32.const 0
"\40" ;; memory.grow
"\80\00" ;; memory.grow reserved byte
"\1a" ;; drop
"\0b" ;; end
)
"zero byte expected"
)
;; Same as above for 3, 4, and 5-byte zero encodings.
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\05\03\01\00\00" ;; Memory section
"\0a\0b\01" ;; Code section
;; function 0
"\09\00"
"\41\00" ;; i32.const 0
"\40" ;; memory.grow
"\80\80\00" ;; memory.grow reserved byte
"\1a" ;; drop
"\0b" ;; end
)
"zero byte expected"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\05\03\01\00\00" ;; Memory section
"\0a\0c\01" ;; Code section
;; function 0
"\0a\00"
"\41\00" ;; i32.const 0
"\40" ;; memory.grow
"\80\80\80\00" ;; memory.grow reserved byte
"\1a" ;; drop
"\0b" ;; end
)
"zero byte expected"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\05\03\01\00\00" ;; Memory section
"\0a\0d\01" ;; Code section
;; function 0
"\0b\00"
"\41\00" ;; i32.const 0
"\40" ;; memory.grow
"\80\80\80\80\00" ;; memory.grow reserved byte
"\1a" ;; drop
"\0b" ;; end
)
"zero byte expected"
)
;; memory.size reserved byte equal to zero.
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\05\03\01\00\00" ;; Memory section
"\0a\07\01" ;; Code section
;; function 0
"\05\00"
"\3f" ;; memory.size
"\01" ;; memory.size reserved byte is not equal to zero!
"\1a" ;; drop
"\0b" ;; end
)
"zero byte expected"
)
;; memory.size reserved byte should not be a "long" LEB128 zero.
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\05\03\01\00\00" ;; Memory section
"\0a\08\01" ;; Code section
;; function 0
"\06\00"
"\3f" ;; memory.size
"\80\00" ;; memory.size reserved byte
"\1a" ;; drop
"\0b" ;; end
)
"zero byte expected"
)
;; Same as above for 3, 4, and 5-byte zero encodings.
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\05\03\01\00\00" ;; Memory section
"\0a\09\01" ;; Code section
;; function 0
"\07\00"
"\3f" ;; memory.size
"\80\80\00" ;; memory.size reserved byte
"\1a" ;; drop
"\0b" ;; end
)
"zero byte expected"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\05\03\01\00\00" ;; Memory section
"\0a\0a\01" ;; Code section
;; function 0
"\08\00"
"\3f" ;; memory.size
"\80\80\80\00" ;; memory.size reserved byte
"\1a" ;; drop
"\0b" ;; end
)
"zero byte expected"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\05\03\01\00\00" ;; Memory section
"\0a\0b\01" ;; Code section
;; function 0
"\09\00"
"\3f" ;; memory.size
"\80\80\80\80\00" ;; memory.size reserved byte
"\1a" ;; drop
"\0b" ;; end
)
"zero byte expected"
)
;; Local number is unsigned 32 bit
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\0a\0c\01" ;; Code section
;; function 0
"\0a\02"
"\80\80\80\80\10\7f" ;; 0x100000000 i32
"\02\7e" ;; 0x00000002 i64
"\0b" ;; end
)
"integer too large"
)
;; Local number is unsigned 32 bit
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\0a\0c\01" ;; Code section
;; function 0
"\0a\02"
"\80\80\80\80\10\7f" ;; 0x100000000 i32
"\02\7e" ;; 0x00000002 i64
"\0b" ;; end
)
"integer too large"
)
;; No more than 2^32-1 locals.
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\0a\0c\01" ;; Code section
;; function 0
"\0a\02"
"\ff\ff\ff\ff\0f\7f" ;; 0xFFFFFFFF i32
"\02\7e" ;; 0x00000002 i64
"\0b" ;; end
)
"too many locals"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\06\01\60\02\7f\7f\00" ;; Type section: (param i32 i32)
"\03\02\01\00" ;; Function section
"\0a\1c\01" ;; Code section
;; function 0
"\1a\04"
"\80\80\80\80\04\7f" ;; 0x40000000 i32
"\80\80\80\80\04\7e" ;; 0x40000000 i64
"\80\80\80\80\04\7d" ;; 0x40000000 f32
"\80\80\80\80\04\7c" ;; 0x40000000 f64
"\0b" ;; end
)
"too many locals"
)
;; Local count can be 0.
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\0a\0a\01" ;; Code section
;; function 0
"\08\03"
"\00\7f" ;; 0 i32
"\00\7e" ;; 0 i64
"\02\7d" ;; 2 f32
"\0b" ;; end
)
;; Function section has non-zero count, but code section is absent.
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\03\02\00\00" ;; Function section with 2 functions
)
"function and code section have inconsistent lengths"
)
;; Code section has non-zero count, but function section is absent.
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\0a\04\01\02\00\0b" ;; Code section with 1 empty function
)
"function and code section have inconsistent lengths"
)
;; Function section count > code section count
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\03\02\00\00" ;; Function section with 2 functions
"\0a\04\01\02\00\0b" ;; Code section with 1 empty function
)
"function and code section have inconsistent lengths"
)
;; Function section count < code section count
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section with 1 function
"\0a\07\02\02\00\0b\02\00\0b" ;; Code section with 2 empty functions
)
"function and code section have inconsistent lengths"
)
;; Function section has zero count, and code section is absent.
(module binary
"\00asm" "\01\00\00\00"
"\03\01\00" ;; Function section with 0 functions
)
;; Code section has zero count, and function section is absent.
(module binary
"\00asm" "\01\00\00\00"
"\0a\01\00" ;; Code section with 0 functions
)
;; Fewer passive segments than data count
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\0c\01\03" ;; Data count section with value 3
"\0b\05\02" ;; Data section with two entries
"\01\00" ;; Passive data section
"\01\00" ;; Passive data section
)
"data count and data section have inconsistent lengths"
)
;; More passive segments than data count
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\0c\01\01" ;; Data count section with value 1
"\0b\05\02" ;; Data section with two entries
"\01\00" ;; Passive data section
"\01\00" ;; Passive data section
)
"data count and data section have inconsistent lengths"
)
;; Non-zero data count section without data section
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\05\03\01\00\01" ;; Memory section with one entry
"\0c\01\01" ;; Data count section with value 1
)
"data count and data section have inconsistent lengths"
)
;; Zero data count section without data section
(module binary
"\00asm" "\01\00\00\00"
"\0c\01\00" ;; Data count section with value 0
)
;; memory.init requires a data count section
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\05\03\01\00\00" ;; Memory section
"\0a\0e\01" ;; Code section
;; function 0
"\0c\00"
"\41\00" ;; zero args
"\41\00"
"\41\00"
"\fc\08\00\00" ;; memory.init
"\0b"
"\0b\03\01\01\00" ;; Data section
) ;; end
"data count section required"
)
;; data.drop requires a data count section
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\05\03\01\00\00" ;; Memory section
"\0a\07\01" ;; Code section
;; function 0
"\05\00"
"\fc\09\00" ;; data.drop
"\0b"
"\0b\03\01\01\00" ;; Data section
) ;; end
"data count section required"
)
;; passive element segment containing illegal opcode
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\04\04\01" ;; Table section with 1 entry
"\70\00\00" ;; no max, minimum 0, funcref
"\05\03\01\00\00" ;; Memory section
"\09\07\01" ;; Element section with one segment
"\05\70" ;; Passive, funcref
"\01" ;; 1 element
"\f3\00\0b" ;; bad opcode, index 0, end
"\0a\04\01" ;; Code section
;; function 0
"\02\00"
"\0b" ;; end
)
"illegal opcode"
)
;; passive element segment containing type other than funcref
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\04\04\01" ;; Table section with 1 entry
"\70\00\00" ;; no max, minimum 0, funcref
"\05\03\01\00\00" ;; Memory section
"\09\07\01" ;; Element section with one segment
"\05\7f" ;; Passive, i32
"\01" ;; 1 element
"\d2\00\0b" ;; ref.func, index 0, end
"\0a\04\01" ;; Code section
;; function 0
"\02\00"
"\0b" ;; end
)
"malformed reference type"
)
;; passive element segment containing opcode ref.func
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\04\04\01" ;; Table section with 1 entry
"\70\00\00" ;; no max, minimum 0, funcref
"\05\03\01\00\00" ;; Memory section
"\09\07\01" ;; Element section with one segment
"\05\70" ;; Passive, funcref
"\01" ;; 1 element
"\d2\00\0b" ;; ref.func, index 0, end
"\0a\04\01" ;; Code section
;; function 0
"\02\00"
"\0b" ;; end
)
;; passive element segment containing opcode ref.null
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\04\04\01" ;; Table section with 1 entry
"\70\00\00" ;; no max, minimum 0, funcref
"\05\03\01\00\00" ;; Memory section
"\09\07\01" ;; Element section with one segment
"\05\70" ;; Passive, funcref
"\01" ;; 1 element
"\d0\70\0b" ;; ref.null, end
"\0a\04\01" ;; Code section
;; function 0
"\02\00"
"\0b" ;; end
)
;; Type count can be zero
(module binary
"\00asm" "\01\00\00\00"
"\01\01\00" ;; type count can be zero
)
;; 2 type declared, 1 given
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\07\02" ;; type section with inconsistent count (2 declared, 1 given)
"\60\00\00" ;; 1st type
;; "\60\00\00" ;; 2nd type (missed)
)
"length out of bounds"
)
;; 1 type declared, 2 given
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\07\01" ;; type section with inconsistent count (1 declared, 2 given)
"\60\00\00" ;; 1st type
"\60\00\00" ;; 2nd type (redundant)
)
"section size mismatch"
)
;; Import count can be zero
(module binary
"\00asm" "\01\00\00\00"
"\01\05\01" ;; type section
"\60\01\7f\00" ;; type 0
"\02\01\00" ;; import count can be zero
)
;; Malformed import kind
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\02\04\01" ;; import section with single entry
"\00" ;; string length 0
"\00" ;; string length 0
"\04" ;; malformed import kind
)
"malformed import kind"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\02\05\01" ;; import section with single entry
"\00" ;; string length 0
"\00" ;; string length 0
"\04" ;; malformed import kind
"\00" ;; dummy byte
)
"malformed import kind"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\02\04\01" ;; import section with single entry
"\00" ;; string length 0
"\00" ;; string length 0
"\05" ;; malformed import kind
)
"malformed import kind"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\02\05\01" ;; import section with single entry
"\00" ;; string length 0
"\00" ;; string length 0
"\05" ;; malformed import kind
"\00" ;; dummy byte
)
"malformed import kind"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\02\04\01" ;; import section with single entry
"\00" ;; string length 0
"\00" ;; string length 0
"\80" ;; malformed import kind
)
"malformed import kind"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\02\05\01" ;; import section with single entry
"\00" ;; string length 0
"\00" ;; string length 0
"\80" ;; malformed import kind
"\00" ;; dummy byte
)
"malformed import kind"
)
;; 2 import declared, 1 given
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\05\01" ;; type section
"\60\01\7f\00" ;; type 0
"\02\16\02" ;; import section with inconsistent count (2 declared, 1 given)
;; 1st import
"\08" ;; string length
"\73\70\65\63\74\65\73\74" ;; spectest
"\09" ;; string length
"\70\72\69\6e\74\5f\69\33\32" ;; print_i32
"\00\00" ;; import kind, import signature index
;; 2nd import
;; (missed)
)
"unexpected end of section or function"
)
;; 1 import declared, 2 given
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\09\02" ;; type section
"\60\01\7f\00" ;; type 0
"\60\01\7d\00" ;; type 1
"\02\2b\01" ;; import section with inconsistent count (1 declared, 2 given)
;; 1st import
"\08" ;; string length
"\73\70\65\63\74\65\73\74" ;; spectest
"\09" ;; string length
"\70\72\69\6e\74\5f\69\33\32" ;; print_i32
"\00\00" ;; import kind, import signature index
;; 2nd import
;; (redundant)
"\08" ;; string length
"\73\70\65\63\74\65\73\74" ;; spectest
"\09" ;; string length
"\70\72\69\6e\74\5f\66\33\32" ;; print_f32
"\00\01" ;; import kind, import signature index
)
"section size mismatch"
)
;; Table count can be zero
(module binary
"\00asm" "\01\00\00\00"
"\04\01\00" ;; table count can be zero
)
;; 1 table declared, 0 given
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\04\01\01" ;; table section with inconsistent count (1 declared, 0 given)
;; "\70\01\00\00" ;; table entity
)
"unexpected end of section or function"
)
;; Malformed table limits flag
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\04\03\01" ;; table section with one entry
"\70" ;; anyfunc
"\02" ;; malformed table limits flag
)
"integer too large"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\04\04\01" ;; table section with one entry
"\70" ;; anyfunc
"\02" ;; malformed table limits flag
"\00" ;; dummy byte
)
"integer too large"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\04\06\01" ;; table section with one entry
"\70" ;; anyfunc
"\81\00" ;; malformed table limits flag as LEB128
"\00\00" ;; dummy bytes
)
"integer representation too long"
)
;; Memory count can be zero
(module binary
"\00asm" "\01\00\00\00"
"\05\01\00" ;; memory count can be zero
)
;; 1 memory declared, 0 given
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\05\01\01" ;; memory section with inconsistent count (1 declared, 0 given)
;; "\00\00" ;; memory 0 (missed)
)
"unexpected end of section or function"
)
;; Malformed memory limits flag
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\05\02\01" ;; memory section with one entry
"\02" ;; malformed memory limits flag
)
"integer too large"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\05\03\01" ;; memory section with one entry
"\02" ;; malformed memory limits flag
"\00" ;; dummy byte
)
"integer too large"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\05\05\01" ;; memory section with one entry
"\81\00" ;; malformed memory limits flag as LEB128
"\00\00" ;; dummy bytes
)
"integer representation too long"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\05\05\01" ;; memory section with one entry
"\81\01" ;; malformed memory limits flag as LEB128
"\00\00" ;; dummy bytes
)
"integer representation too long"
)
;; Global count can be zero
(module binary
"\00asm" "\01\00\00\00"
"\06\01\00" ;; global count can be zero
)
;; 2 global declared, 1 given
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\06\06\02" ;; global section with inconsistent count (2 declared, 1 given)
"\7f\00\41\00\0b" ;; global 0
;; "\7f\00\41\00\0b" ;; global 1 (missed)
)
"unexpected end of section or function"
)
;; 1 global declared, 2 given
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\06\0b\01" ;; global section with inconsistent count (1 declared, 2 given)
"\7f\00\41\00\0b" ;; global 0
"\7f\00\41\00\0b" ;; global 1 (redundant)
)
"section size mismatch"
)
;; Export count can be 0
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01" ;; type section
"\60\00\00" ;; type 0
"\03\03\02\00\00" ;; func section
"\07\01\00" ;; export count can be zero
"\0a\07\02" ;; code section
"\02\00\0b" ;; function body 0
"\02\00\0b" ;; function body 1
)
;; 2 export declared, 1 given
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01" ;; type section
"\60\00\00" ;; type 0
"\03\03\02\00\00" ;; func section
"\07\06\02" ;; export section with inconsistent count (2 declared, 1 given)
"\02" ;; export 0
"\66\31" ;; export name
"\00\00" ;; export kind, export func index
;; "\02" ;; export 1 (missed)
;; "\66\32" ;; export name
;; "\00\01" ;; export kind, export func index
"\0a\07\02" ;; code section
"\02\00\0b" ;; function body 0
"\02\00\0b" ;; function body 1
)
"length out of bounds"
)
;; 1 export declared, 2 given
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01" ;; type section
"\60\00\00" ;; type 0
"\03\03\02\00\00" ;; func section
"\07\0b\01" ;; export section with inconsistent count (1 declared, 2 given)
"\02" ;; export 0
"\66\31" ;; export name
"\00\00" ;; export kind, export func index
"\02" ;; export 1 (redundant)
"\66\32" ;; export name
"\00\01" ;; export kind, export func index
"\0a\07\02" ;; code section
"\02\00\0b" ;; function body 0
"\02\00\0b" ;; function body 1
)
"section size mismatch"
)
;; elem segment count can be zero
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01" ;; type section
"\60\00\00" ;; type 0
"\03\02\01\00" ;; func section
"\04\04\01" ;; table section
"\70\00\01" ;; table 0
"\09\01\00" ;; elem segment count can be zero
"\0a\04\01" ;; code section
"\02\00\0b" ;; function body
)
;; 2 elem segment declared, 1 given
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01" ;; type section
"\60\00\00" ;; type 0
"\03\02\01\00" ;; func section
"\04\04\01" ;; table section
"\70\00\01" ;; table 0
"\09\07\02" ;; elem with inconsistent segment count (2 declared, 1 given)
"\00\41\00\0b\01\00" ;; elem 0
;; "\00\41\00\0b\01\00" ;; elem 1 (missed)
)
"unexpected end"
)
;; 2 elem segment declared, 1.5 given
(assert_malformed
(module binary