Skip to content

Fix GH-22570: stack overflow serializing a deeply nested Dom\XMLDocument#22576

Closed
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-22570-dom-xml-serialize-stack
Closed

Fix GH-22570: stack overflow serializing a deeply nested Dom\XMLDocument#22576
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-22570-dom-xml-serialize-stack

Conversation

@iliaal

@iliaal iliaal commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

A deeply nested Dom\XMLDocument overflows the C stack when serialized, since the XML serializer recurses per element child. Adds a stack-limit check at the dispatcher (throwing an Error on overflow, like bd724bd for var serialization) and gates the saveXml warning and innerHTML exception with !EG(exception) so the thrown Error isn't masked or replaced.

Fixes #22570

…cument

The new-DOM XML serializer recurses through dom_xml_serialization_algorithm()
for every element child, so a document nested deeply enough overflows the C
stack and crashes during saveXml() or innerHTML. Add a stack-limit check at
the dispatcher, throwing an Error on overflow, mirroring bd724bd. Gate the
"Could not save document" warning and the innerHTML not-well-formed exception
with !EG(exception) so the thrown Error propagates cleanly instead of being
accompanied by a warning or replaced with the wrong exception type.

Fixes phpGH-22570
@iliaal iliaal closed this in dd57694 Jul 3, 2026
@iluuu1994

Copy link
Copy Markdown
Member

The test seems to fail frequently in nightly. Can you please check?

https://github.com/php/php-src/actions/runs/28725922777/job/85183280824

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.

Stack overflow when serializing a deeply nested Dom\XMLDocument

3 participants