Skip to content

Fix GH-23120: DOMNode::isEqualNode stack overflow on deeply nested trees - #23140

Merged
LamentXU123 merged 4 commits into
php:PHP-8.4from
LamentXU123:dom-fix-overflow
Aug 8, 2026
Merged

Fix GH-23120: DOMNode::isEqualNode stack overflow on deeply nested trees#23140
LamentXU123 merged 4 commits into
php:PHP-8.4from
LamentXU123:dom-fix-overflow

Conversation

@LamentXU123

Copy link
Copy Markdown
Member

DOMNode::isEqualNode() recursively compared ordered child lists.

Compare each node without descending into its children first to solve this and we walk both subtrees in tree order to compare descendants iteratively.

Fix GH-23120

@devnexen

devnexen commented Aug 8, 2026

Copy link
Copy Markdown
Member

I would rather prefer you control the stack limit ; also, for once, the CI arm issue is very related (timeout?).

Comment thread ext/dom/node.c Outdated
ZEND_ASSERT(other != NULL);

if (UNEXPECTED(php_dom_node_is_equal_node_check_stack_limit())) {
zend_throw_error(NULL, "Maximum call stack size reached. Infinite recursion?");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it needs to be gated with the exception global.

Comment thread ext/dom/node.c Outdated

if (UNEXPECTED(php_dom_node_is_equal_node_check_stack_limit())) {
if (!EG(exception)) {
zend_throw_error(NULL, "Maximum call stack size reached. Infinite recursion?");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be infinite recursion because a tree is an acyclic graph

Suggested change
zend_throw_error(NULL, "Maximum call stack size reached. Infinite recursion?");
zend_throw_error(NULL, "Maximum call stack size reached.");

@LamentXU123 LamentXU123 Aug 8, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct! I copy-paste this message from the last fix #23127 and I overlook this. Thx

@LamentXU123
LamentXU123 merged commit c4c356a into php:PHP-8.4 Aug 8, 2026
18 checks passed
LamentXU123 added a commit that referenced this pull request Aug 8, 2026
* PHP-8.5:
  Fix GH-23120: DOMNode::isEqualNode stack overflow on deeply nested trees (#23140)
NickSdot pushed a commit to NickSdot/php__php-src that referenced this pull request Aug 8, 2026
* PHP-8.4:
  Fix phpGH-23120: DOMNode::isEqualNode stack overflow on deeply nested trees (php#23140)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants