WebAssembly / WebAssembly/wabt

Assertion `enum_ == Enum::Reference' failed at wasm2wat

Open
#1,986 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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 ()

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.

Research direction

Reproduce the crash with wasm2wat --enable-all ./poc.wasm using the attached poc_wasm2wat.wasm, then inspect src/type.h, type-checker.cc, shared-validator.cc, and validator.cc along the reported stack. Trace the OnCallRef validation path and ensure this input no longer aborts on the assertion, with the resulting behavior covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, wasm
Domain
compilers, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.