Skip to content

Commit 943492a

Browse files
sbc100fgmccabe
authored andcommitted
Add tests for functions without end marker. NFC (#1405)
Inspired by this downstream test in wabt: WebAssembly/wabt#1775 Fixes: #1404
1 parent 480af1a commit 943492a

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/core/binary.wast

+56
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,62 @@
368368
"integer too large"
369369
)
370370

371+
;; Function with missing end marker (between two functions)
372+
(assert_malformed
373+
(module binary
374+
"\00asm" "\01\00\00\00"
375+
"\01\04\01\60\00\00" ;; Type section: 1 type
376+
"\03\03\02\00\00" ;; Function section: 2 functions
377+
"\0a\0c\02" ;; Code section: 2 functions
378+
;; function 0
379+
"\04\00" ;; Function size and local type count
380+
"\41\01" ;; i32.const 1
381+
"\1a" ;; drop
382+
;; Missing end marker here
383+
;; function 1
384+
"\05\00" ;; Function size and local type count
385+
"\41\01" ;; i32.const 1
386+
"\1a" ;; drop
387+
"\0b" ;; end
388+
)
389+
"END opcode expected"
390+
)
391+
392+
;; Function with missing end marker (at EOF)
393+
(assert_malformed
394+
(module binary
395+
"\00asm" "\01\00\00\00"
396+
"\01\04\01\60\00\00" ;; Type section: 1 type
397+
"\03\02\01\00" ;; Function section: 1 function
398+
"\0a\06\01" ;; Code section: 1 function
399+
;; function 0
400+
"\04\00" ;; Function size and local type count
401+
"\41\01" ;; i32.const 1
402+
"\1a" ;; drop
403+
;; Missing end marker here
404+
)
405+
"unexpected end of section or function"
406+
)
407+
408+
;; Function with missing end marker (at end of code sections)
409+
(assert_malformed
410+
(module binary
411+
"\00asm" "\01\00\00\00"
412+
"\01\04\01\60\00\00" ;; Type section: 1 type
413+
"\03\02\01\00" ;; Function section: 1 function
414+
"\0a\06\01" ;; Code section: 1 function
415+
;; function 0
416+
"\04\00" ;; Function size and local type count
417+
"\41\01" ;; i32.const 1
418+
"\1a" ;; drop
419+
;; Missing end marker here
420+
"\0b\03\01\01\00" ;; Data section
421+
)
422+
;; The spec interpreter consumes the `\0b` (data section start) as an
423+
;; END instruction (also happens to be `\0b`) and reports the code section as
424+
;; being larger than declared.
425+
"section size mismatch"
426+
)
371427

372428
;; Unsigned LEB128 must not be overlong
373429
(assert_malformed

0 commit comments

Comments
 (0)