WebAssembly / WebAssembly/wabt

[wasm-validate] Wrong binary location reported in error message

Open
#1,217 4 comments 0 reactions 1 assignee View on GitHub

@ajklein is already working on this.

Since Apr 6, 2020.

good-first-bug
Dominant language
C++
Stars
8.1k
Forks
827
Avg merge
4d 6h
Merged PRs (30d)
18

Description

Hi,
I believe that wasm-validate reports the wrong binary location in its error messages.

Example

Validating following file generated via wast2json from the spec test i32.wast

$ xxd test/core/wasm/i32/i32.wast.8.wasm
00000000: 0061 736d 0100 0000 0104 0160 0000 0302  .asm.......`....
00000010: 0100 0a0e 010c 0041 0002 4045 0e00 001a  .......A..@E....
00000020: 0b0b                                     ..

$ wasm-objdump -d test/core/wasm/i32/i32.wast.8.wasm 

i32.wast.8.wasm:        file format wasm 0x1

Code Disassembly:

000016 func[0]:
 000017: 41 00                      | i32.const 0
 000019: 02 40                      | block
 00001b: 45                         |   i32.eqz
 00001c: 0e 00 00                   |   br_table
 00001f: 1a                         |   drop
 000020: 0b                         | end
 000021: 0b                         | end

with the wasm-validate program results in following error message:

$ wasm-validate test/core/wasm/i32/i32.wast.8.wasm
test/core/wasm/i32/i32.wast.8.wasm:000001c: error: type mismatch in i32.eqz, expected [i32] but got []
test/core/wasm/i32/i32.wast.8.wasm:0000021: error: type mismatch in function, expected [] but got [i32]

However, as can be seen in the object dump above the i32.eqz instruction (hex opcode 45) is at offset 000001b, not 000001c as stated in the error message. Interestingly, the second error message displays the correct binary location.

Expected Output

To clarify, I would have expected following output:

$ wasm-validate test/core/wasm/i32/i32.wast.8.wasm
test/core/wasm/i32/i32.wast.8.wasm:000001b: error: type mismatch in i32.eqz, expected [i32] but got []
test/core/wasm/i32/i32.wast.8.wasm:0000021: error: type mismatch in function, expected [] but got [i32]

Additional Information

The spec interpreter reports the correct binary location:

$ wasm test/core/wasm/i32/i32.wast.8.wasm
../spec/core/wasm/i32/i32.wast.8.wasm:0x1b: invalid module: type mismatch: operator requires [i32] but stack has []

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.