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