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