fix(scanner): avoid out-of-bounds read of valid_symbols during error recovery - #258
Open
xcthulhu wants to merge 1 commit into
Open
fix(scanner): avoid out-of-bounds read of valid_symbols during error recovery#258xcthulhu wants to merge 1 commit into
xcthulhu wants to merge 1 commit into
Conversation
…recovery Removes the invalid `valid_symbols[ERROR_SENTINEL]` access and instead detects error recovery by checking only the real, in-range token slots (`RAW_STRING_BEGIN` / `RAW_STRING_CONTENT` / `RAW_STRING_END`).
xcthulhu
force-pushed
the
fix-scanner-oob-read
branch
from
August 25, 2026 15:26
1f1b4a2 to
34b6afc
Compare
Contributor
|
Is it possible to have tests that support these changes? |
Author
The failure is only reproducible with AddressSanitizer; I could incorporate it into your git workflow if you want. |
Contributor
|
Never heard of it. Do you have a link to it where I can read up on it? I doubt we'd want to add it to our CI. |
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.
Fixes #257
What
Fixes a global-buffer-overflow in the external scanner (
src/scanner.c).Root cause
The scanner reads
valid_symbols[ERROR_SENTINEL](around line 116), butERROR_SENTINELis not a declared external token — only 3 tokens are declared inexternals, sovalid_symbolsis sized for 3 and the index reads past the end of the array.Fix
Removes the invalid
valid_symbols[ERROR_SENTINEL]access and instead detects error recovery by checking only the real, in-range token slots (RAW_STRING_BEGIN/RAW_STRING_CONTENT/RAW_STRING_END).The patch was generated with LLM assistance and auto-verified: after applying it and
rebuilding at the tested commit, the crashing input no longer triggers the bug when replayed
under the same libFuzzer + AddressSanitizer time / memory budget. Please review it on those
terms — it may include incidental reformatting.
Provenance
Found with an automated libFuzzer + AddressSanitizer fuzzing pipeline, as part of a research
project on hardening tree-sitter grammars. A self-contained reproducer is available on
request (see the linked issue).