diff options
author | Ng Zhi An <zhin@google.com> | 2023-02-13 02:16:44 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-13 10:16:44 +0000 |
commit | 4bf38aaefa33bcf89a8e707b406c49090c5a00e3 (patch) | |
tree | 48cdd95426bc2fe4c40ed1842425a9b0c5fc8528 | |
parent | 330d3a0e914504420902fa4b58af4645a06a969e (diff) | |
download | wabt-4bf38aaefa33bcf89a8e707b406c49090c5a00e3.tar.gz wabt-4bf38aaefa33bcf89a8e707b406c49090c5a00e3.tar.bz2 wabt-4bf38aaefa33bcf89a8e707b406c49090c5a00e3.zip |
objdump: take care of opcodes whose bytes are non-canonical leb128 (#1632)
Fixes #1631
-rw-r--r-- | src/binary-reader-objdump.cc | 5 | ||||
-rw-r--r-- | test/dump/noncanon-leb128-opcode.txt | 39 |
2 files changed, 43 insertions, 1 deletions
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc index eac21ef3..23f2016f 100644 --- a/src/binary-reader-objdump.cc +++ b/src/binary-reader-objdump.cc @@ -587,7 +587,10 @@ Result BinaryReaderObjdumpDisassemble::OnOpcode(Opcode opcode) { } if (last_opcode_end) { - if (state->offset != last_opcode_end + opcode.GetLength()) { + // Takes care of cases where opcode's bytes was a non-canonical leb128 + // encoding. In this case, opcode.GetLength() under-reports the length, + // since it canonicalizes the opcode. + if (state->offset < last_opcode_end + opcode.GetLength()) { Opcode missing_opcode = Opcode::FromCode(data_[last_opcode_end]); const char* opcode_name = missing_opcode.GetName(); fprintf(stderr, diff --git a/test/dump/noncanon-leb128-opcode.txt b/test/dump/noncanon-leb128-opcode.txt new file mode 100644 index 00000000..785dc9dd --- /dev/null +++ b/test/dump/noncanon-leb128-opcode.txt @@ -0,0 +1,39 @@ +;;; TOOL: run-objdump-spec +;;; ARGS0: -v +;;; ARGS1: %(temp_file)s.0.wasm +(module binary +"\00\61\73\6d\01\00\00\00\01\0a\02\60\00\01\7f\60\01\7f\01\7f\03\02\01\01\04\05\01\70\01\01\09\07\08\01\04\6d\61\69\6e\00\00\0a\27\01\25\01\03\7e\20\00\41\d6\49\02\7f\41\fe\20\0c\00\68\fc\0e\00\00\0b\20\00\68\fc\10\00\68\fc\90\80\00\00\00\26\00\0b" +) +(;; STDERR ;;; +0000000: 0061 736d 0100 0000 010a 0260 0001 7f60 +0000010: 017f 017f 0302 0101 0405 0170 0101 0907 +0000020: 0801 046d 6169 6e00 000a 2701 2501 037e +0000030: 2000 41d6 4902 7f41 fe20 0c00 68fc 0e00 +0000040: 000b 2000 68fc 1000 68fc 9080 0000 0026 +0000050: 000b ; +;;; STDERR ;;) +(;; STDOUT ;;; + +noncanon-leb128-opcode.0.wasm: file format wasm 0x1 + +Code Disassembly: + +00002d func[0] <main>: + 00002e: 03 7e | local[0..2] type=i64 + 000030: 20 00 | local.get 0 + 000032: 41 d6 49 | i32.const 4294960342 + 000035: 02 7f | block i32 + 000037: 41 fe 20 | i32.const 4222 + 00003a: 0c 00 | br 0 + 00003c: 68 | i32.ctz + 00003d: fc 0e 00 00 | table.copy 0 0 + 000041: 0b | end + 000042: 20 00 | local.get 0 + 000044: 68 | i32.ctz + 000045: fc 10 00 | table.size 0 + 000048: 68 | i32.ctz + 00004b: 80 00 00 | table.size 0 + 00004e: 00 | unreachable + 00004f: 26 00 | table.set 0 + 000051: 0b | end +;;; STDOUT ;;) |