Skip to content

AOT: appendChild/insertBefore/replaceChild(foreign Element) skip Wrong Document — LiveSlots only guards Document (#22710/#30274) #33937

Closed

Description

@PurHur

Category

bug · AOT / ext/dom · php-src-strict

Problem

Thin-AOT LiveSlots preflight assertTreeMutationChildBeforeLiveSlots only rejects Document-class children (#30274). Foreign Element (and other tree nodes) from another DOMDocument are accepted and linked — Zend throws DOMException code 4 (Wrong Document Error). VM matches Zend. createElement foreign append can SIGSEGV after the skipped guard.

Repro Zend 8.x VM AOT (master)
$d1->documentElement->appendChild($d2->documentElement->firstChild) code=4 Wrong Document Error same NO_THROW / silent move
insertBefore / replaceChild same pattern (#22710/#22711 fixtures) code=4 same NO_THROW
$d1->documentElement->appendChild($d2->createElement('b')) code=4 same SIGSEGV

Also: test/compliance/cases/dom/dom_node_insertbefore_wrong_document.phpt is green on VM and red on AOT.

php-src reference

  • php/php-src ext/dom/node.c — dom_node_append_child / insert_before / replace_child → WRONG_DOCUMENT_ERR via same-document check before hierarchy rejection

PHP implementation target

Repro

./script/docker-exec.sh -- bash -lc 'php -r "
\$d1=new DOMDocument(); \$d1->loadXML(\"<r><a/></r>\");
\$d2=new DOMDocument(); \$d2->loadXML(\"<r><b/></r>\");
try { \$d1->documentElement->appendChild(\$d2->documentElement->firstChild); echo \"NO_THROW\\n\"; }
catch (DOMException \$e) { echo \"code=\", \$e->getCode(), \" msg=\", \$e->getMessage(), \"\\n\"; }
"'
# Then same source via bin/compile.php + run binary — expect code=4

Done when

  • AOT matches Zend/VM: foreign Element appendChild/insertBefore/replaceChild → DOMException code 4
  • createElement foreign append throws (no SIGSEGV)
  • Compliance dom_node_insertbefore_wrong_document / dom_node_replacechild_wrong_document green under AOT
  • ./script/aot-smoke.sh stays 8/8

Activity

  1. added
    bugSomething isn't working
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Aug 22, 2026
  2. PurHur commented on Aug 22, 2026

    @PurHur
    OwnerAuthor

    claim: DOM/XML specialist working this run — extend assertTreeMutationChildBeforeLiveSlots for foreign Element Wrong Document (re-#22710/#30274).

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

    area:compilerCompiler / CFG / JITbugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions