WebAssembly / WebAssembly/wabt

Assertion `enum_ == Enum::Reference' failed at wasm-validate

Open
#1,987 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_wasm-validate.wasm
poc_wasm-validate.wasm.zip

Stack dump
$ ./wasm-validate --enable-all poc_wasm-validate.wasm
wasm-validate: ../../../../src/type.h:132: wabt::Index wabt::Type::GetReferenceIndex() const: Assertion `enum_ == Enum::Reference' failed.
Aborted

$ gdb  ./wasm-validate
pwndbg> r --enable-all ./8858c8fd6729859-id\:000000\,sig\:06\,src\:000000\,time\:152726\,execs\:15118\,op\:havoc\,rep\:4.wasm
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
wasm-validate: ../../../../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  0x7fffffff8c30 ◂— 0x0
 R8   0x0
 R9   0x7fffffff8c30 ◂— 0x0
 R10  0x8
 R11  0x246
 R12  0x785a80 (str) ◂— '../../../../src/type.h'
 R13  0x84
 R14  0x785a40 (str) ◂— 'enum_ == Enum::Reference'
 R15  0x0
 RBP  0x7ffff7bf0588 ◂— "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n"
 RSP  0x7fffffff8c30 ◂— 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 0x7fffffff8c30 ◂— 0x0
01:0008│            0x7fffffff8c38 —▸ 0x4ba4d0 (free) ◂— push   rbp
02:0010│            0x7fffffff8c40 ◂— 0x7ffffbad8000
03:0018│            0x7fffffff8c48 —▸ 0x612000000340 ◂— 0xc800001
04:0020│            0x7fffffff8c50 —▸ 0x6120000003a5 ◂— "on `enum_ == Enum::Reference' failed.\n"
05:0028│            0x7fffffff8c58 —▸ 0x612000000340 ◂— 0xc800001
06:0030│            0x7fffffff8c60 —▸ 0x612000000340 ◂— 0xc800001
07:0038│            0x7fffffff8c68 —▸ 0x6120000003cb ◂— 0x0
─────────────────────────────────────────────────────────────────────────────────[ BACKTRACE ]──────────────────────────────────────────────────────────────────────────────────
 ► f 0   0x7ffff7a7b00b raise+203
   f 1   0x7ffff7a5a859 abort+299
   f 2   0x7ffff7a5a729 _nl_load_domain.cold
   f 3   0x7ffff7a6bfd6
   f 4         0x7238c8
   f 5         0x715885
   f 6         0x6d93dd
   f 7         0x5f912d
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
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=0x785a40 <str> "enum_ == Enum::Reference", file=0x785a80 <str> "../../../../src/type.h", line=132, function=<optimized out>) at assert.c:92
#3  0x00007ffff7a6bfd6 in __GI___assert_fail (assertion=0x785a40 <str> "enum_ == Enum::Reference", file=0x785a80 <str> "../../../../src/type.h", line=132, function=0x785ac0 <__PRETTY_FUNCTION__._ZNK4wabt4Type17GetReferenceIndexEv> "wabt::Index wabt::Type::GetReferenceIndex() const") at assert.c:101
#4  0x00000000007238c8 in wabt::Type::GetReferenceIndex (this=0x7fffffff8f70) at ../../../../src/type.h:132
#5  0x0000000000715885 in wabt::TypeChecker::OnIndexedFuncRef (this=0x7fffffffd568, out_index=0x7fffffff9200) at ../../../../src/type-checker.cc:536
#6  0x00000000006d93dd in wabt::SharedValidator::OnCallRef (this=0x7fffffffd548, loc=..., function_type_index=0x7fffffff94b0) at ../../../../src/shared-validator.cc:706
#7  0x00000000005f912d in wabt::(anonymous namespace)::Validator::OnCallRefExpr (this=0x7fffffffd530, expr=0x60d000000380) at ../../../../src/validator.cc:281
#8  0x00000000006a82ba in wabt::ExprVisitor::HandleDefaultState (this=0x7fffffffc0f0, expr=0x60d000000380) at ../../../../src/expr-visitor.cc:219
#9  0x00000000006a408e in wabt::ExprVisitor::VisitExpr (this=0x7fffffffc0f0, root_expr=0x60d000000380) at ../../../../src/expr-visitor.cc:41
#10 0x00000000006adc5f in wabt::ExprVisitor::VisitExprList (this=0x7fffffffc0f0, exprs=...) at ../../../../src/expr-visitor.cc:148
#11 0x00000000005f33a8 in wabt::(anonymous namespace)::Validator::CheckModule (this=0x7fffffffd530) at ../../../../src/validator.cc:830
#12 0x00000000005ed6de in wabt::ValidateModule (module=0x7fffffffda10, errors=0x7fffffffd9d0, options=...) at ../../../../src/validator.cc:1044
#13 0x00000000004efb42 in ProgramMain (argc=3, argv=0x7fffffffe178) at ../../../../src/tools/wasm-validate.cc:88
#14 0x00000000004f01a2 in main (argc=3, argv=0x7fffffffe178) at ../../../../src/tools/wasm-validate.cc:97
#15 0x00007ffff7a5c083 in __libc_start_main (main=0x4f0180 <main(int, char**)>, argc=3, argv=0x7fffffffe178, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe168) at ../csu/libc-start.c:308
#16 0x000000000043e00e 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

Start with the wasm-validate entry point in src/tools/wasm-validate.cc and follow the reported path through src/validator.cc, src/shared-validator.cc, src/type-checker.cc, and src/type.h. Run wasm-validate --enable-all on the supplied poc_wasm-validate.wasm; done means the input no longer aborts on the reported assertion and is handled as validation output.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
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.