Skip to content

Fix long validation of array.new-fixed in unreachable code - #2688

Merged
alexcrichton merged 2 commits into
bytecodealliance:mainfrom
alexcrichton:validate-new-fixed-faster
Sep 29, 2026
Merged

alexcrichton merged 2 commits into
bytecodealliance:mainfrom
alexcrichton:validate-new-fixed-faster

Conversation

@alexcrichton

Copy link
Copy Markdown
Member

This commit fixes an issue in wasmparser where validation of array.new-fixed in unreachable code would take O(n) time where n was the immediate on array.new-fixed. It's valid for unreachable code to have array.new-fixed $a 0xff..ff for example because unreachable is polymorphic in its stack, but wasmparser's previous implementation would pop each individual operand from the stack (getting MaybeType::Bottom a low), and this took time linear to the magnitude of the immediate as opposed to linear in the size of the code itself. This meant it was pretty easy to generate a small module that takes ~forever to validate, which generally is not a property we want to have.

This commit fixes an issue in `wasmparser` where validation of
`array.new-fixed` in unreachable code would take `O(n)` time where `n`
was the immediate on `array.new-fixed`. It's valid for unreachable code
to have `array.new-fixed $a 0xff..ff` for example because `unreachable`
is polymorphic in its stack, but wasmparser's previous implementation
would pop each individual operand from the stack (getting
`MaybeType::Bottom` a low), and this took time linear to the magnitude
of the immediate as opposed to linear in the size of the code itself.
This meant it was pretty easy to generate a small module that takes
~forever to validate, which generally is not a property we want to have.
@alexcrichton
alexcrichton requested a review from a team as a code owner September 28, 2026 20:16
@alexcrichton
alexcrichton added this pull request to the merge queue Sep 29, 2026
Merged via the queue into bytecodealliance:main with commit 1e37de8 Sep 29, 2026
37 checks passed
@alexcrichton
alexcrichton deleted the validate-new-fixed-faster branch September 29, 2026 22:33
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