From a73b049e2a86bea2280248967f76489ac4ff75cb Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 10 Dec 2021 11:49:00 -0800 Subject: [PATCH] Add tests for functions without end marker. NFC Inspired by this downstream test in wabt: https://github.com/WebAssembly/wabt/pull/1775 Fixes: #1404 --- test/core/binary.wast | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/core/binary.wast b/test/core/binary.wast index ebebd2eada..e80d3e20b5 100644 --- a/test/core/binary.wast +++ b/test/core/binary.wast @@ -368,6 +368,62 @@ "integer too large" ) +;; Function with missing end marker (between two functions) +(assert_malformed + (module binary + "\00asm" "\01\00\00\00" + "\01\04\01\60\00\00" ;; Type section: 1 type + "\03\03\02\00\00" ;; Function section: 2 functions + "\0a\0c\02" ;; Code section: 2 functions + ;; function 0 + "\04\00" ;; Function size and local type count + "\41\01" ;; i32.const 1 + "\1a" ;; drop + ;; Missing end marker here + ;; function 1 + "\05\00" ;; Function size and local type count + "\41\01" ;; i32.const 1 + "\1a" ;; drop + "\0b" ;; end + ) + "END opcode expected" +) + +;; Function with missing end marker (at EOF) +(assert_malformed + (module binary + "\00asm" "\01\00\00\00" + "\01\04\01\60\00\00" ;; Type section: 1 type + "\03\02\01\00" ;; Function section: 1 function + "\0a\06\01" ;; Code section: 1 function + ;; function 0 + "\04\00" ;; Function size and local type count + "\41\01" ;; i32.const 1 + "\1a" ;; drop + ;; Missing end marker here + ) + "unexpected end of section or function" +) + +;; Function with missing end marker (at end of code sections) +(assert_malformed + (module binary + "\00asm" "\01\00\00\00" + "\01\04\01\60\00\00" ;; Type section: 1 type + "\03\02\01\00" ;; Function section: 1 function + "\0a\06\01" ;; Code section: 1 function + ;; function 0 + "\04\00" ;; Function size and local type count + "\41\01" ;; i32.const 1 + "\1a" ;; drop + ;; Missing end marker here + "\0b\03\01\01\00" ;; Data section + ) + ;; The spec interpreter consumes the `\0b` (data section start) as an + ;; END instruction (also happens to be `\0b`) and reports the code section as + ;; being larger than declared. + "section size mismatch" +) ;; Unsigned LEB128 must not be overlong (assert_malformed