Skip to content

Assertion failure in ext/dom/parentnode/tree.c #16151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chibinz opened this issue Oct 1, 2024 · 1 comment
Closed

Assertion failure in ext/dom/parentnode/tree.c #16151

chibinz opened this issue Oct 1, 2024 · 1 comment

Comments

@chibinz
Copy link

chibinz commented Oct 1, 2024

Description

The following code:

<?php

$comment = new DOMComment ( "h" );
$element = new DOMElement ( "N" , "W" , "y" );
$attr = new DOMAttr ( "c" , "n" );
$doc = new DOMDocument (  );
$doc -> adoptNode ( $element );
$element -> setAttributeNodeNS ( $attr );
$attr -> insertBefore ( $comment );
$comment -> replaceWith ( "Q" );

Resulted in this output:

php: /tmp/php-afl/ext/dom/parentnode/tree.c:243: _Bool dom_is_pre_insert_valid_without_step_1(php_libxml_ref_obj *, xmlNodePtr, xmlNodePtr, xmlNodePtr, xmlDocPtr): Assertion `!php_dom_pre_insert_is_parent_invalid(parentNode)' failed.

But I expected this output instead:

no crash

PHP Version

PHP 8.4.0-dev

Operating System

No response

@nielsdos
Copy link
Member

nielsdos commented Oct 1, 2024

Problem is that the constraints of the DOM tree are broken because a comment is inserted as a child of an attribute, this should not be possible. This is because the old DOM doesn't follow spec, bleh

nielsdos added a commit to nielsdos/php-src that referenced this issue Oct 1, 2024
Unfortunately, old DOM allows attributes to be used as parent nodes.
Only text nodes and entities are allowed as children for these types of
nodes, because that's the constraint DOM and libxml give us.
nielsdos added a commit that referenced this issue Oct 1, 2024
* PHP-8.2:
  Fix GH-16151: Assertion failure in ext/dom/parentnode/tree.c
nielsdos added a commit that referenced this issue Oct 1, 2024
* PHP-8.3:
  Fix GH-16151: Assertion failure in ext/dom/parentnode/tree.c
nielsdos added a commit that referenced this issue Oct 1, 2024
* PHP-8.4:
  Fix GH-16151: Assertion failure in ext/dom/parentnode/tree.c
jorgsowa pushed a commit to jorgsowa/php-src that referenced this issue Oct 1, 2024
Unfortunately, old DOM allows attributes to be used as parent nodes.
Only text nodes and entities are allowed as children for these types of
nodes, because that's the constraint DOM and libxml give us.

Closes phpGH-16156.
jorgsowa pushed a commit to jorgsowa/php-src that referenced this issue Oct 1, 2024
Unfortunately, old DOM allows attributes to be used as parent nodes.
Only text nodes and entities are allowed as children for these types of
nodes, because that's the constraint DOM and libxml give us.

Closes phpGH-16156.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants