Skip to content

Fix out-of-bounds write in MakeTypeBindingReverseMapping#2796

Merged
sbc100 merged 2 commits into
WebAssembly:mainfrom
aizu-m:type-binding-reverse-oob
Jul 13, 2026
Merged

Fix out-of-bounds write in MakeTypeBindingReverseMapping#2796
sbc100 merged 2 commits into
WebAssembly:mainfrom
aizu-m:type-binding-reverse-oob

Conversation

@aizu-m

@aizu-m aizu-m commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

ASan, release build, wasm2wat on a crafted module:

==…==ERROR: AddressSanitizer: heap-buffer-overflow
  #0 wabt::MakeTypeBindingReverseMapping(...) ir.cc
  #1 wabt::ApplyNames(wabt::Module*)
  #2 ProgramMain
... located 1535 bytes after 24-byte region

Found while going over the name-section handlers. The local subsection stores a (local index, name) pair per entry. OnLocalNameLocalCount checks the entry count against the function's param+local count, but the per-entry local index in OnLocalName is never range-checked before it becomes a Binding. MakeTypeBindingReverseMapping sizes the reverse map to that local count and writes each name at binding.index, guarded only by an assert. 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 .wasm through wasm2wat and wasm2c (both call ApplyNames and 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 wasm2wat aborts, after it prints the module with the stray name dropped.

@@ -0,0 +1,34 @@
;;; TOOL: run-gen-wasm
;; The name section's local subsection can carry a local index that is out of

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, the entry is bad data so the bad- prefix fits. Renamed it to bad-name-section-local-index.txt and pushed.

@sbc100
sbc100 merged commit 2a8dc8b into WebAssembly:main Jul 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