Skip to content

Reject delegate depth overflow in TypeChecker::OnDelegate - #2841

Merged
sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:delegate-depth-overflow
Aug 30, 2026
Merged

sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:delegate-depth-overflow

Conversation

@aizu-m

@aizu-m aizu-m commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

wat2wasm and wasm-validate on a try...delegate with depth 0xffffffff:

$ wat2wasm bad.wat -o bad.wasm     # accepted
$ wasm-validate bad.wasm ; echo $? # 0

Spotted wasm-validate passing a module that wasm-interp then hangs on. TypeChecker::OnDelegate resolves the delegate target with GetLabel(depth + 1), as the depth counts from after the try being closed. depth is a u32 taken straight from the module. For depth == 0xffffffff the depth + 1 wraps to 0, and GetLabel(0) always succeeds, so the bounds check never fires. delegate 0xfffffffe is still rejected ("invalid depth: 4294967295 (max 2)"); only the exact wrap slips through.

Downstream the interp builds the handler from GetNearestTryLabel(depth + 1), i.e. GetNearestTryLabel(0), which returns the try being closed. The try delegates to itself, and Thread::DoThrow loops on the self-referential handler.

Rejecting depth == kInvalidIndex before the add closes both the wat and binary paths. Every in-range delegate is untouched.

@sbc100
sbc100 merged commit 974221b into WebAssembly:main Aug 30, 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