wabt
wabt copied to clipboard
Assertion `enum_ == Enum::Reference' failed at wasm2wat
Environment
OS : Linux ubuntu 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Commit : 3054d61f703d609995798f872fc86b462617c294
Version : 1.0.29
Build : make clang-debug-asan
Proof of concept
poc_wasm2wat.wasm poc_wasm2wat.wasm.zip
Stack dump
gdb /wabt/out/clang/Debug/asan/wasm2wat
pwndbg> r --enable-all ./poc.wasm
Starting program: /wabt/out/clang/Debug/asan/wasm2wat --enable-all ./poc.wasm
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
wasm2wat: ../../../../src/type.h:132: wabt::Index wabt::Type::GetReferenceIndex() const: Assertion `enum_ == Enum::Reference' failed.
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
─────────────────────────────────────────────────────────────────────────────────[ REGISTERS ]──────────────────────────────────────────────────────────────────────────────────
RAX 0x0
RBX 0x7ffff7a357c0 ◂— 0x7ffff7a357c0
RCX 0x7ffff7a7b00b (raise+203) —▸ 0x10824848b48 ◂— 0x0
RDX 0x0
RDI 0x2
RSI 0x7fffffff8b70 ◂— 0x0
R8 0x0
R9 0x7fffffff8b70 ◂— 0x0
R10 0x8
R11 0x246
R12 0x7e5b60 (str) ◂— '../../../../src/type.h'
R13 0x84
R14 0x7e5b20 (str) ◂— 'enum_ == Enum::Reference'
R15 0x0
RBP 0x7ffff7bf0588 ◂— "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n"
RSP 0x7fffffff8b70 ◂— 0x0
RIP 0x7ffff7a7b00b (raise+203) —▸ 0x10824848b48 ◂— 0x0
───────────────────────────────────────────────────────────────────────────────────[ DISASM ]───────────────────────────────────────────────────────────────────────────────────
► 0x7ffff7a7b00b <raise+203> mov rax, qword ptr [rsp + 0x108]
0x7ffff7a7b013 <raise+211> xor rax, qword ptr fs:[0x28]
0x7ffff7a7b01c <raise+220> jne raise+260 <raise+260>
↓
0x7ffff7a7b044 <raise+260> call __stack_chk_fail <__stack_chk_fail>
0x7ffff7a7b049 nop dword ptr [rax]
0x7ffff7a7b050 <killpg> endbr64
0x7ffff7a7b054 <killpg+4> test edi, edi
0x7ffff7a7b056 <killpg+6> js killpg+16 <killpg+16>
0x7ffff7a7b058 <killpg+8> neg edi
0x7ffff7a7b05a <killpg+10> jmp kill <kill>
0x7ffff7a7b05f <killpg+15> nop
───────────────────────────────────────────────────────────────────────────────────[ STACK ]────────────────────────────────────────────────────────────────────────────────────
00:0000│ rsi r9 rsp 0x7fffffff8b70 ◂— 0x0
01:0008│ 0x7fffffff8b78 —▸ 0x4ba570 (free) ◂— push rbp
02:0010│ 0x7fffffff8b80 ◂— 0x7562205dfbad8000
03:0018│ 0x7fffffff8b88 —▸ 0x612000000340 ◂— 0x52800001
04:0020│ 0x7fffffff8b90 —▸ 0x6120000003a5 ◂— "num_ == Enum::Reference' failed.\n"
05:0028│ 0x7fffffff8b98 —▸ 0x612000000340 ◂— 0x52800001
06:0030│ 0x7fffffff8ba0 —▸ 0x612000000340 ◂— 0x52800001
07:0038│ 0x7fffffff8ba8 —▸ 0x6120000003c6 ◂— 0x0
─────────────────────────────────────────────────────────────────────────────────[ BACKTRACE ]──────────────────────────────────────────────────────────────────────────────────
► f 0 0x7ffff7a7b00b raise+203
f 1 0x7ffff7a5a859 abort+299
f 2 0x7ffff7a5a729 _nl_load_domain.cold
f 3 0x7ffff7a6bfd6
f 4 0x779a68
f 5 0x76bd05
f 6 0x72fc4d
f 7 0x62d45d
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
pwndbg> bt
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007ffff7a5a859 in __GI_abort () at abort.c:79
#2 0x00007ffff7a5a729 in __assert_fail_base (fmt=0x7ffff7bf0588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x7e5b20 <str> "enum_ == Enum::Reference", file=0x7e5b60 <str> "../../../../src/type.h", line=132, function=<optimized out>) at assert.c:92
#3 0x00007ffff7a6bfd6 in __GI___assert_fail (assertion=0x7e5b20 <str> "enum_ == Enum::Reference", file=0x7e5b60 <str> "../../../../src/type.h", line=132, function=0x7e5ba0 <__PRETTY_FUNCTION__._ZNK4wabt4Type17GetReferenceIndexEv> "wabt::Index wabt::Type::GetReferenceIndex() const") at assert.c:101
#4 0x0000000000779a68 in wabt::Type::GetReferenceIndex (this=0x7fffffff8eb0) at ../../../../src/type.h:132
#5 0x000000000076bd05 in wabt::TypeChecker::OnIndexedFuncRef (this=0x7fffffffd4a8, out_index=0x7fffffff9140) at ../../../../src/type-checker.cc:536
#6 0x000000000072fc4d in wabt::SharedValidator::OnCallRef (this=0x7fffffffd488, loc=..., function_type_index=0x7fffffff93f0) at ../../../../src/shared-validator.cc:706
#7 0x000000000062d45d in wabt::(anonymous namespace)::Validator::OnCallRefExpr (this=0x7fffffffd470, expr=0x60d000000110) at ../../../../src/validator.cc:281
#8 0x00000000005c666a in wabt::ExprVisitor::HandleDefaultState (this=0x7fffffffc030, expr=0x60d000000110) at ../../../../src/expr-visitor.cc:219
#9 0x00000000005c243e in wabt::ExprVisitor::VisitExpr (this=0x7fffffffc030, root_expr=0x60d000000110) at ../../../../src/expr-visitor.cc:41
#10 0x00000000005cc00f in wabt::ExprVisitor::VisitExprList (this=0x7fffffffc030, exprs=...) at ../../../../src/expr-visitor.cc:148
#11 0x00000000006276d8 in wabt::(anonymous namespace)::Validator::CheckModule (this=0x7fffffffd470) at ../../../../src/validator.cc:830
#12 0x0000000000621a0e in wabt::ValidateModule (module=0x7fffffffd950, errors=0x7fffffffd910, options=...) at ../../../../src/validator.cc:1044
#13 0x00000000004efd87 in ProgramMain (argc=3, argv=0x7fffffffe218) at ../../../../src/tools/wasm2wat.cc:120
#14 0x00000000004f0af2 in main (argc=3, argv=0x7fffffffe218) at ../../../../src/tools/wasm2wat.cc:147
#15 0x00007ffff7a5c083 in __libc_start_main (main=0x4f0ad0 <main(int, char**)>, argc=3, argv=0x7fffffffe218, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe208) at ../csu/libc-start.c:308
#16 0x000000000043e0ae in _start ()
Thanks very much for this. AFAIK support for function-references remains a work in progress in WABT -- we're not running the function-references tests and I don't think we really support these instructions yet. (See https://github.com/WebAssembly/wabt/pull/1695) This codepath can only be hit behind --enable-function-references (or --enable-all in this case). Leaving open for now.