Repository navigation
Bounds-check the octal prefix skip in pm_integer_parse - #4353
Closed
fuzzyrichie wants to merge 1 commit into
Closed
fuzzyrichie wants to merge 1 commit into
fuzzyrichie wants to merge 1 commit into
Conversation
After skipping the leading `0` of an octal literal, pm_integer_parse dereferences `start` to look for an `o`/`_` prefix without checking it against `end`. If the token were exactly "0", that would read one byte past the token, and past the source buffer if the token ended it. The lexer never hands pm_integer_parse such a token today: a bare `0` has its value computed during lexing, and every token that does reach the octal branch is at least two bytes long. Check `start < end` anyway so the function stays in bounds for any token it is given, matching how the lexer guards its own lookahead with peek(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
No. This is adding a check for something that never happens. |
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.
Background
In
pm_integer_parse, the octal case skips the leading0and then dereferencesstartto look for ano/O/_prefix, without checking it againstend:If the token were exactly
"0", this would read one byte past the token, and past the source buffer if the token ended it.Impact
None today. The lexer never passes
pm_integer_parsesuch a token:0has its value computed during lexing (parser->integer.start == token->start), sopm_integer_node_createnever callspm_integer_parsefor it;00,0_7,0o17,017r, ...) is at least two bytes long.I checked this with an ASan build that parses exact-size heap buffers with no NUL terminator.
0,x = 0,00,0_,0o,0r,0i,07and the other base prefixes are all clean before and after this change.Fix
Check
start < endbefore the prefix lookahead. This keeps the function in bounds for any token it's given, the same way the lexer guards its own lookahead withpeek(). It has no effect on any token the lexer produces today.src/integer.ccompiles cleanly with prism's-Werror -Wconversion -Wpedanticflags.🤖 Generated with Claude Code