Fix PHP re2c scanner state machine translation bugs#3
Merged
niden merged 8 commits intophalcon:masterfrom Apr 8, 2026
Merged
Conversation
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.
Summary:
Scanner::scanForToken()— bounds check was only at function entry; added it inside the outer while(IMPOSSIBLE) loop so cursor overruns during a single call are also caught$yychthen used a bare break 2 which in PHP exits both the enclosing switch and thewhile(true), discarding the read value and resetting the state machine to state 0. Fixed by removing the explicit$yystate/break 2 and letting execution fall through to the successor casesubstroffset to capture the full [identifier] value including bracketsscanForToken()calls; value, opcode, and len are now reset to null/0 at the start of each callRoot cause: In
switch($yystate), a bare break 2 exits both the switch and the enclosingwhile(true). However, break 2 from inside a nestedswitch($yych)only exits the two switch levels, allowing the while to continue. States that performed a read-then-transition without a nested switch all shared this bug, silently resetting the state machine to state 0 and losing accumulated scan progress.Test plan: