Repository navigation
Fix memory-safety crash on invalid UTF-8 variable names - #602
Merged
Merged
Conversation
GrahamCampbell
changed the base branch from
master
to
types/option-result-precision
August 24, 2026 10:42
GrahamCampbell
force-pushed
the
fix/utf8-name-validation-modifier
branch
from
August 24, 2026 10:42
b3d755d to
cc880ae
Compare
GrahamCampbell
force-pushed
the
types/option-result-precision
branch
2 times, most recently
from
August 24, 2026 17:28
8b76297 to
46e982e
Compare
GrahamCampbell
force-pushed
the
fix/utf8-name-validation-modifier
branch
from
August 24, 2026 17:28
558a54a to
5249b62
Compare
GrahamCampbell
force-pushed
the
fix/utf8-name-validation-modifier
branch
from
August 24, 2026 17:43
5249b62 to
1c2769e
Compare
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.
Variable-name validation enabled PCRE UTF-8 mode with the in-pattern (*UTF8) verb rather than the u modifier, so PHP never checked that the subject was valid UTF-8 before matching. On a malformed byte sequence reaching Dotenv::parse or Parser::parse, where string input is not passed through the file reader's UTF-8 normalisation, the matcher reads past the end of the subject buffer, producing nondeterministic accept and reject results and a reproducible segmentation fault. Switching to the u modifier makes PHP validate the subject and reject invalid UTF-8 deterministically, which is exactly what name validation intends, and leaves every valid ASCII and UTF-8 name untouched. The name grammar itself, the export prefix strip, the quote delimiter checks and their length guard, is now handled with byte operations too, because running it through mbstring meant that on PHP 8.3.2 and later with a non-default substitute character configured, the replacement of malformed bytes could synthesise a valid-looking name, quote pair or export prefix and let an invalid name slip past validation, in the worst case colliding with a legitimate key defined earlier in the file. This is intended to land before v5.7.0 is tagged.