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