Fix GH-23116 and GH-23117: stack overflow when normalizing a deeply nested document - #23127
Closed
lazerg wants to merge 2 commits into
Closed
Fix GH-23116 and GH-23117: stack overflow when normalizing a deeply nested document#23127lazerg wants to merge 2 commits into
lazerg wants to merge 2 commits into
Conversation
lazerg
force-pushed
the
fix/gh-23116-23117-dom-normalize-stack-limit
branch
from
August 8, 2026 05:23
ad54d80 to
8be21fc
Compare
Member
|
nit: can we exercise this test somewhere ? $doc = new DOMDocument();
$root = $doc->createElement('root');
for ($s = 0; $s < 2; $s++) {
$node = $doc->createElement('a');
for ($i = 0; $i < 100000; $i++) {
$parent = $doc->createElement('a');
$parent->appendChild($node);
$node = $parent;
}
$root->appendChild($node);
}
$doc->appendChild($root);
try {
$doc->normalize();
} catch (\Error $e) {
echo "wide: ", $e::class, ": ", $e->getMessage(), "\n";
**var_dump($e->getPrevious());**
}
expecting
wide: Error: Maximum call stack size reached. Infinite recursion?
NULL |
…eply nested document
lazerg
force-pushed
the
fix/gh-23116-23117-dom-normalize-stack-limit
branch
from
August 8, 2026 05:39
8be21fc to
86d9b4a
Compare
lazerg
force-pushed
the
fix/gh-23116-23117-dom-normalize-stack-limit
branch
from
August 8, 2026 05:42
c03b193 to
8fb1d7c
Compare
Contributor
Author
|
Added. Both tests now build two deep branches under one root and assert that I also moved the tests off |
devnexen
approved these changes
Aug 8, 2026
LamentXU123
approved these changes
Aug 8, 2026
Member
|
Thanks! |
pull Bot
pushed a commit
to KornaPhp/php-src
that referenced
this pull request
Aug 8, 2026
* PHP-8.4: Fix phpGH-23116 and phpGH-23117: stack overflow when normalizing a deeply nested document (php#23127)
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.
DOMNode::normalize()andDom\Node::normalize()walk the tree by recursing once per element child, so a deeply nested document exhausts the C stack and segfaults. Both now check the stack limit on entry and throw anError, the same way the XML serializer has since GH-22570.The throw is gated on
EG(exception)because these functions return void: without it, unwinding through a tree that is wide at the overflow depth throws once per node and chains the Errors, which is quadratic.Fixes #23116
Fixes #23117