Repository navigation
Conversation
zend_multibyte_yyinput_again() re-converts the whole script with the new input filter, but kept the cursor at the byte offset it had in the old filtered buffer. When the code before declare(encoding=...) converts to a different length under the new encoding, scanning resumed before or after the end of the declare, which caused parse errors, silently skipped code, or reads past the end of the new buffer. Map the cursor back to the source offset through the old filter and forward through the new one. The backward search, shared with zend_get_scanned_file_offset(), becomes a bisection for the shortest source prefix whose conversion starts with the scanned bytes: it needs O(log n) conversions instead of one per byte, and it ends on a character boundary even when a truncated character converts to a substitute of a different length.
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.
With zend.multibyte on,
declare(encoding=...)re-converts the script with the new encoding but keeps the scanner cursor at its byte offset in the old converted buffer. When the code before the declare converts to a different length, scanning resumes at the wrong place, so valid scripts fail to parse or skip code, and a shorter conversion such as UTF-32 leaves the cursor past the end of the buffer. Map the cursor back to a source offset through the old filter and forward through the new one. The backward search shared withzend_get_scanned_file_offset()becomes a bisection, so it stops on a character boundary even when a truncated unit converts to a substitute.