Skip to content

Fix container-overflow in BinaryReaderInterp (#2747) - #2812

Closed
ANAMASGARD wants to merge 2 commits into
WebAssembly:mainfrom
ANAMASGARD:fix/interp-function-body-oob
Closed

Fix container-overflow in BinaryReaderInterp (#2747)#2812
ANAMASGARD wants to merge 2 commits into
WebAssembly:mainfrom
ANAMASGARD:fix/interp-function-body-oob

Conversation

@ANAMASGARD

Copy link
Copy Markdown

Fixes #2747

Summary

  • Add OnFunctionBodyCount guard to BinaryReaderInterp to prevent container-overflow when stop_on_first_error=false and the Function section fails before all FuncDesc entries are appended.
  • Guard uses count != module_.funcs.size() (interp stores defined funcs only, unlike IR reader).
  • Add regression test with the 18-byte PoC from OOB read in wabt Interpreter Binary Reader #2747.

Test plan

  • ./wabt-unittests --gtest_filter='InterpTest.FunctionBodyCountMismatchWithCollectErrors'
  • ./wabt-unittests
  • PoC with stop_on_first_error=false returns error without crash

image

When stop_on_first_error=false, a failed OnFunction left module_.funcs
empty while OnFunctionCount had reserved capacity. BeginFunctionBody then
wrote past the vector's logical end (ASan container-overflow).
Add OnFunctionBodyCount guard matching the established BinaryReaderIR
pattern, adapted for interp where module_.funcs holds defined funcs only.
Fixes WebAssembly#2747

Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
Wrap comments and reformat the PoC byte array to satisfy
scripts/clang-format-diff.sh.

Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
@sbc100

sbc100 commented Aug 8, 2026

Copy link
Copy Markdown
Member

If this only applies with stop_on_first_error=false then i don't think we need to fix it since the interpreter should never be run in this mode.

@ANAMASGARD

Copy link
Copy Markdown
Author

@sbc100 You're right — I rechecked and this only reproduces with stop_on_first_error=false. wasm-interp / spectest-interp / the interp fuzzer all force stop-on-first-error=true, and ReadBinaryOptions defaults to that as well.

So this isn't a bug in the supported interpreter path. I'll close this PR (and #2747) as not applicable. Thanks for the clarification.

@ANAMASGARD ANAMASGARD closed this Aug 9, 2026
@sbc100

sbc100 commented Aug 9, 2026

Copy link
Copy Markdown
Member

We should probably add an assert or something if interp (or other tools) are used with stop_on_first_error=false?

@sbc100

sbc100 commented Aug 9, 2026

Copy link
Copy Markdown
Member

i.e. only certain readers are compatible with this mode and we should make that more clear

@ANAMASGARD

Copy link
Copy Markdown
Author

@sbc100 Makes sense. Happy to follow up with a small PR that asserts (or returns Error) in ReadBinaryInterp when stop_on_first_error=false, plus a short comment that only readers designed for collect-errors mode (e.g.
BinaryReaderIR / objdump) support that option.

Should that be assert-only (debug), or also reject in release builds?
Please give your feedback @sbc100 should I open a new PR or not ??

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.

OOB read in wabt Interpreter Binary Reader

2 participants