Repository navigation
[ExpressionLanguage] Fix nesting level of chained ternaries - #66720
Merged
nicolas-grekas merged 1 commit intoOct 9, 2026
Merged
Conversation
Contributor
Author
|
The Fabbot typo check fails on "does't" in an existing ParserTest comment that this PR does not change. The Unit Tests (8.3) failure is in HttpClient ( |
nicolas-grekas
requested review from
OskarStark,
chalasr,
dunglas,
lyrixx,
xabbuh and
yceruto
as code owners
October 9, 2026 11:05
nicolas-grekas
force-pushed
the
fix/issue-66719-ternary-nesting-level
branch
from
October 9, 2026 11:05
028aa06 to
0f90393
Compare
Member
|
Thank you @lazerg. |
nicolas-grekas
added a commit
that referenced
this pull request
Oct 9, 2026
…ee (nicolas-grekas) This PR was merged into the 5.4 branch. Discussion ---------- [ExpressionLanguage] Bound the depth of the parsed node tree | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Follows #65690: the nesting level misses the levels that a chain of binary operators or of property accesses adds above its first operand. With `p` nested parentheses holding `k` additions each, as in `((1 + 1 + 1) + 1 + 1)`, an expression costs about `p + k` levels but builds a tree `p × k` levels deep. With `p = k = 60`, the expression is accepted and `serialize()`, which the default cache of `ExpressionLanguage` runs on parsed expressions, segfaults on PHP 8.1 and 8.2 (8.3+ throws "Maximum call stack size reached"). This also checks the depth of the node tree once parsed. A tree is at most one level deeper than its number of tokens, so the walk is skipped for expressions shorter than 256 characters. Merge-up to 6.4: keep `unset($this->stream, $this->names);` after the new check and use `\sprintf()` in `checkDepth()` (trial-merged and tested up to 8.2, together with #66720). Commits ------- 944be84 [ExpressionLanguage] Bound the depth of the parsed node tree
This was referenced Oct 14, 2026
Merged
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.
Since #65690, a chain of ternaries can hit the nesting limit even when the tree is shallow.
str_repeat('a and a and a ? 1 : ', 64).'0'is rejected, but the same expression with brackets around each condition is accepted.parseExpression()adds one level for each binary operator of the condition. It kept these levels when it parsed thethenandelsebranches. In a chain, the operator counts of all conditions add up. The branches are siblings of the condition, not children. So the level is now reset beforeparseConditionalExpression()runs, the same way brackets already do it.Deep chains are still rejected: the existing
ternariescase passes, and 300 chained? :,?:or??still throw. I added a test with the expression from the issue. It fails without the fix../phpunit src/Symfony/Component/ExpressionLanguagepasses (385 tests).