Repository navigation
[Yaml] Throw a ParseException on keys starting with a NUL byte when parsing mappings as objects - #66830
Merged
nicolas-grekas merged 1 commit intoOct 12, 2026
Conversation
…arsing mappings as objects
Contributor
Author
|
The "Unit Tests (8.4, high-deps)" failure is not caused by this change: Composer got an empty zip for symfony/dependency-injection while it installed the FrameworkBundle dependencies, so the tests did not run. |
xabbuh
approved these changes
Oct 12, 2026
Member
|
Thank you @lazerg. |
This was referenced Oct 14, 2026
Merged
Merged
Merged
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
Yaml::PARSE_OBJECT_FOR_MAP, a mapping key that starts with a NUL byte crashes the block parser with a PHP\Error, because PHP does not allow such property names onstdClass. Code that catchesParseExceptiondoes not catch it.The inline parser does not crash, because it uses an
(object)cast. But the cast gives a broken object:{ "\0": 1 }gets an inaccessible property, and{ "\0*\0x": 1 }gets a protected property namedx. So both parsers now throw the sameParseExceptionwhen they read such a key with the flag. Keys with a NUL byte in other positions ("a\0b") are valid property names and still work. Without the flag, nothing changes.Tests:
ParserTest::testKeyStartingWithNulByteThrowsParseExceptionWhenMappingsAreParsedAsObjectsandInlineTest::testParseKeyStartingWithNulByteWithMapObjectsThrowsParseExceptionfail without the fix. The Yaml test suite passes on 6.4 (934 tests). I also cherry-picked the commit onto 7.4, 8.1 and 8.2 without conflicts, and the Yaml suite passes on 8.2.