Fix out-of-bounds write in MakeTypeBindingReverseMapping#2796
Merged
Conversation
sbc100
reviewed
Jul 12, 2026
| @@ -0,0 +1,34 @@ | |||
| ;;; TOOL: run-gen-wasm | |||
| ;; The name section's local subsection can carry a local index that is out of | |||
Member
There was a problem hiding this comment.
Should we give the test the bad- prefix, since the name section in this case contains bad data?
How about bad-name-section-local-index or bad-local-index-in-name-section ?
Contributor
Author
There was a problem hiding this comment.
Agreed, the entry is bad data so the bad- prefix fits. Renamed it to bad-name-section-local-index.txt and pushed.
sbc100
approved these changes
Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ASan, release build,
wasm2waton a crafted module:Found while going over the name-section handlers. The local subsection stores a (local index, name) pair per entry.
OnLocalNameLocalCountchecks the entry count against the function's param+local count, but the per-entry local index inOnLocalNameis never range-checked before it becomes aBinding.MakeTypeBindingReverseMappingsizes the reverse map to that local count and writes each name atbinding.index, guarded only by anassert. A name whose index sits past the function's locals writes off the end of the vector: a debug build trips the assert, a release build corrupts the heap. Reached from an untrusted.wasmthroughwasm2watandwasm2c(both callApplyNamesand read debug names by default), on an otherwise valid module.Skip entries that land outside the mapping. Valid modules only name real locals, so their output does not change. The added test names local index 5 of a one-param function; before the fix
wasm2wataborts, after it prints the module with the stray name dropped.