Skip to content

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

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

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

Conversation

@iliaal

@iliaal iliaal commented Jul 3, 2026

Copy link
Copy Markdown
Owner

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 php#22570

@iliaal iliaal force-pushed the fix/gh-22570-dom-xml-serialize-stack branch from 25e6c84 to 117177a Compare July 3, 2026 11:20
…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 force-pushed the fix/gh-22570-dom-xml-serialize-stack branch from 117177a to f52a02c Compare July 3, 2026 12:23
@iliaal

iliaal commented Jul 3, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#22576, closing this.

@iliaal iliaal closed this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant