Skip to content

Reject DTD declaration nodes in modern DOM adoptNode() #25750

Done

Description

@imattas

Summary

On current php-src master, Dom\Document::adoptNode() accepts DTD declaration nodes exposed through the modern DOM API as Dom\Entity. Adopting an XML_ELEMENT_DECL or XML_ENTITY_DECL into another document mutates libxml ownership while the node remains owned by the source DTD. The call returns, then the process crashes during document teardown (ASan reports a read in xmlFreeDocElementContent/xmlFreeDtd in the tested build).

Reproduction

$source = Dom\XMLDocument::createFromString('<!DOCTYPE r [<!ELEMENT r EMPTY>]><r/>');
$target = Dom\XMLDocument::createFromString('<target/>');
$target->adoptNode($source->doctype->childNodes->item(0));

Expected: reject unsupported DTD declarations with NotSupportedError before changing ownership.

This is distinct from #23352, which concerns stale PHP wrappers for attribute-value text nodes after adoption. This report concerns native ownership of the DTD declaration nodes themselves.

Activity

  1. nwellnhof commented on Nov 26, 2026

    @nwellnhof

    In libxml2, it's generally unsafe to move DTD-related nodes between documents, so this might affect other functions as well.

  2. imattas commented on Nov 26, 2026

    @imattas
    ContributorAuthor

    should this be closed then?

  3. nwellnhof commented on Nov 26, 2026

    @nwellnhof

    No, I'm just saying that other code in PHP might be affected as well.

  4. added a commit that references this issue on Nov 27, 2026
    5835cf2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions