Skip to content

fix(scanner): avoid out-of-bounds read of valid_symbols during error recovery - #258

Open
xcthulhu wants to merge 1 commit into
nushell:mainfrom
xcthulhu:fix-scanner-oob-read
Open

fix(scanner): avoid out-of-bounds read of valid_symbols during error recovery#258
xcthulhu wants to merge 1 commit into
nushell:mainfrom
xcthulhu:fix-scanner-oob-read

Conversation

@xcthulhu

Copy link
Copy Markdown

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), but ERROR_SENTINEL is not a declared external token — only 3 tokens are declared in externals, so valid_symbols is 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).

…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
xcthulhu force-pushed the fix-scanner-oob-read branch from 1f1b4a2 to 34b6afc Compare August 25, 2026 15:26
@fdncred

fdncred commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Is it possible to have tests that support these changes?

@xcthulhu

Copy link
Copy Markdown
Author

Is it possible to have tests that support these changes?

The failure is only reproducible with AddressSanitizer; I could incorporate it into your git workflow if you want.

@fdncred

fdncred commented Aug 28, 2026

Copy link
Copy Markdown
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.

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.

Out-of-bounds read (global-buffer-overflow) in the external scanner

2 participants