Skip to content

source-map: validate file and symbol indices against array bounds - #9345

Open
TristanInSec wants to merge 2 commits into
WebAssembly:mainfrom
TristanInSec:fix-sourcemap-oob
Open

TristanInSec wants to merge 2 commits into
WebAssembly:mainfrom
TristanInSec:fix-sourcemap-oob

Conversation

@TristanInSec

Copy link
Copy Markdown

The VLQ-decoded file and symbol indices in the source map reader are delta-encoded and accumulated with +=, but never checked against the actual size of the sources/names arrays. A malformed source map can make them go out of range, which causes an OOB vector access later in Print.cpp when looking up debugInfoFileNames[fileIndex].

This stores the array sizes during parse() and rejects out-of-range indices in readDebugLocationAt().

@TristanInSec
TristanInSec requested a review from a team as a code owner November 4, 2026 17:09
@TristanInSec
TristanInSec requested review from kripken and removed request for a team November 4, 2026 17:09

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces bounds checking for VLQ-decoded file and symbol indices in the SourceMapReader to prevent out-of-bounds access by tracking the sizes of debugInfoFileNames and debugInfoSymbolNames. The review feedback points out a critical issue where the guards numFiles > 0 and numSymbols > 0 allow out-of-bounds indices to bypass validation when the respective arrays are empty. Removing these guards ensures that any index is correctly rejected when there are no files or symbols available.

Comment thread src/wasm/source-map.cpp Resolved
Comment thread src/wasm/source-map.cpp Resolved
The VLQ-decoded file and symbol indices in the source map reader
are accumulated without checking that they stay within the
sources/names arrays. A crafted source map can push them out of
range, causing an OOB read when the indices are later used to
look up debugInfoFileNames or debugInfoSymbolNames.

Store the array sizes during parse() and reject out-of-range
indices in readDebugLocationAt().

@kripken kripken left a comment

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.

Thanks, this looks correct, but please add a unit test in test/gtest/source-map.cpp

Add two tests that verify out-of-range VLQ-decoded file and symbol
indices are rejected with MapParseException during readDebugLocationAt.

This branch has not been deployed

No deployments
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