Skip to content

Avoid Var::name() on function-level branches in decompiler - #2762

Merged
sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:decompiler-funclevel-branch
Jun 19, 2026
Merged

sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:decompiler-funclevel-branch

Conversation

@aizu-m

@aizu-m aizu-m commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Found while fuzzing wasm-decompile.

Assertion failed: (is_name()), function name, file ir.h, line 82.

A branch whose target is the function's implicit outermost label is left as an index by the name resolution passes, since there is no block label to attach to it. DecompileExpr then called Var::name() on that index var. ir.h keeps index_ and name_ in a union, so this reads the inactive std::string member; with NDEBUG the assert is gone and it dereferences a garbage pointer instead.

Smallest repro, decompiles to a return:

(func (block (loop (br 2))))

br_if and br_table with a function-level target reach the same path. Routed the three branch sites through a helper that emits return when the target is unnamed.

A branch to the function's implicit outermost label is left as an index by name resolution, so Var::name() read the inactive std::string union member. Route br/br_if/br_table through a helper that emits return for an unnamed target.
@sbc100

sbc100 commented Jun 19, 2026

Copy link
Copy Markdown
Member

I think maybe we should should delete the decompiler since its not maintained at all, and I'm not sure it has any users either.

@sbc100
sbc100 merged commit 80b6582 into WebAssembly:main Jun 19, 2026
17 checks passed
@aizu-m

aizu-m commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

No objection from me. It does look unmaintained, and there's a fair bit of this class of bug still lurking in there. This at least stops the crash for anyone still using it in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants