Commit 2a8dc8b
authored
Fix out-of-bounds write in MakeTypeBindingReverseMapping (#2796)
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.1 parent 33328a0 commit 2a8dc8b
2 files changed
Lines changed: 41 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
605 | 605 | | |
606 | 606 | | |
607 | 607 | | |
608 | | - | |
609 | | - | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
610 | 615 | | |
611 | 616 | | |
612 | 617 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
0 commit comments