Skip to content

[wasm-decompile] Avoid out-of-range shift in load/store rewrite - #2758

Merged
sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:decompiler-shift-exponent
Jun 13, 2026
Merged

sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:decompiler-shift-exponent

Conversation

@aizu-m

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

Copy link
Copy Markdown
Contributor

UBSan, decompiling a module that addresses memory as (base + (index << n)):

src/decompiler.cc:325:21: runtime error: shift exponent 64 is too large for 64-bit type 'unsigned long long'
    #0 wabt::Decompiler::LoadStore(...) decompiler.cc:325
    #1 wabt::Decompiler::DecompileExpr(...) decompiler.cc:489

The load/store printer recognises that address shape and tries to rewrite it to base[index], testing 1ULL << n against the access alignment. n is the i32.const operand of the i32.shl, read straight from the module. i32.shl masks its shift amount at runtime, so n is otherwise unconstrained; n >= 64 pushes the exponent past the width of the type and the shift is undefined.

Bounding n < 64 before the shift loses no real match, since the alignment it is compared against is always a small power of two. The unmatched shape then prints verbatim, the same as a mismatched shift already does.

Repro is a load of (local 0 + (local 1 << 64)): UBSan aborts at decompiler.cc:325 before, decompiles to (a + (b << 64))[0]:int after. Covered by the loadstore decompile test.

@sbc100 sbc100 changed the title Avoid out-of-range shift in decompiler load/store rewrite [wasm-decompile] Avoid out-of-range shift in load/store rewrite Jun 13, 2026
@sbc100 sbc100 changed the title [wasm-decompile] Avoid out-of-range shift in load/store rewrite [wasm-decompile] Avoid out-of-range shift in load/store rewrite Jun 13, 2026
@sbc100
sbc100 merged commit 68db1c1 into WebAssembly:main Jun 13, 2026
17 checks passed
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