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