Repository navigation
Bounds-check function index in name section local handlers - #2787
Conversation
|
I'm not sure we want to support See the discussion in #2778 |
|
Agreed. I went through the callers after reading the #2778 thread: every in-tree ReadBinaryIr user already runs with stop_on_first_error=true (wasm2wat sets it explicitly, the wasm2wat fuzzer and the emscripten helpers get the default). objdump is the only tool that still wants false, and it goes through its own reader, not the IR one. So dropping collect-all-errors mode from the IR path wouldn't cost any tool, just the option surface. Can put that together as a follow-up if that's the direction you'd like. Thanks for merging this one. |
ASAN, calling
ReadBinaryIrwithread_debug_names=trueandstop_on_first_error=falseon a crafted module:Found while going over the name-section handlers.
OnLocalNameLocalCountandOnLocalNameindexmodule_->funcs[func_index]using the function index taken from the name section's local subsection. The reader only checksfunction_index < NumTotalFuncs(), i.e. the declared countnum_func_imports_ + num_function_signatures_. Withstop_on_first_erroroff, a truncated function section (declares two funcs, but the second signature LEB runs past the section end) leavesfuncsone short of that count, so a local name for the missing function reads past the vector.OnLocalNameLocalCounthad a debug-only assert;OnLocalNamehad no check at all.Every sibling handler here already does the
index >= size()check, andOnFunctionBodyCountalready guards this samestop_on_first_errorcase for the code path. Added the matching check to both local-name handlers, plus a regression test.