Repository navigation
Fix out-of-bounds read when tracing global.set and table ops - #2802
Merged
Merged
Conversation
spectest-interp --trace on a module that imports a global and also
defines one, ASan build:
==73766==ERROR: AddressSanitizer: heap-buffer-overflow on address
0x60e0000002a4
READ of size 8 at 0x60e0000002a4 thread T0
WebAssembly#1 Thread::TraceSource::GetGlobalType(unsigned int) interp.cc:3022
WebAssembly#2 Thread::TraceSource::Pick(unsigned int, Instr) interp.cc:2954
WebAssembly#3 Istream::Trace(...) istream.cc:887
0x60e0000002a4 is located 12 bytes after 152-byte region
ModuleDesc::globals and ModuleDesc::tables hold only the defined
entries; imports live in ModuleDesc::imports. The global.set/table.*
immediate is the module-level index and counts imports first, so one
imported global plus one defined global already runs off the end.
GetTableElementType has the same shape.
The garbage ValueType that comes back decides how the operand Value is
read, so a debug build aborts on the CheckType assert in interp.h and a
release build prints an arbitrary reference index.
Resolve both immediates against the instance instead, which is what the
GlobalSet, DoTableGrow and DoTableFill handlers already do.
sbc100
approved these changes
Jul 29, 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,
spectest-interp --traceon a module that imports a global and also defines one:Noticed it while reading the trace helpers.
ModuleDesc::globalsandModuleDesc::tableshold only the defined entries, imports live inModuleDesc::imports. But theglobal.set/table.*immediate is the module-level index, which counts imports first. One imported global plus one defined global is already enough to run off the end.GetTableElementTypehas the same shape at interp.cc:3026, reached fromtable.growandtable.fill.The garbage
ValueTypethat comes back then decides how the operandValueis read, so a debug build aborts on theCheckTypeassert in interp.h and a release build prints an arbitrary reference index.Both immediates now resolve against the instance, which is what the
GlobalSet,DoTableGrowandDoTableFillhandlers already do. Regression test added under test/interp.