Skip to content

Assertion failure in ext/dom/element.c #15910

Closed

Description

@YuanchengJiang

Description

The following code:

<?php
$doc = new DOMDocument();
$doc->appendChild($doc->createElement('container'));
var_dump($doc->documentElement->setAttributeNodeNS($doc)?->nodeValue);

Resulted in this output:

/php-src/ext/dom/element.c:696: dom_element_set_attribute_node_common: Assertion `attrp->type == XML_ATTRIBUTE_NODE' failed.
Aborted (core dumped)

PHP Version

PHP 8.4.0-dev

Operating System

ubuntu 22.04

Activity

  1. cmb69 commented on Sep 16, 2024

    @cmb69
    Member

    php-src/ext/dom/element.c

    Lines 686 to 696 in b438e2b

    if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &node, dom_get_node_ce(modern)) == FAILURE) {
    RETURN_THROWS();
    }
    DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
    DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
    /* ZPP Guarantees that a DOMAttr class is given, as it is converted to a xmlAttr
    * to pass to libxml (see http://www.xmlsoft.org/html/libxml-tree.html#xmlAttr)
    * if it is not of type XML_ATTRIBUTE_NODE it indicates a bug somewhere */
    ZEND_ASSERT(attrp->type == XML_ATTRIBUTE_NODE);

    @nielsdos, the comment doesn't match the ZPP. Should ZPP be changed to dom_get_attr_ce(modern)?

  2. changed the title [-]Core dumped in ext/dom/element.c[/-] [+]Assertion failure in ext/dom/element.c[/+] on Sep 16, 2024
  3. ndossche commented on Sep 16, 2024

    @ndossche
    Member

    Indeed, fixed.

  4. added a commit that references this issue on Sep 16, 2024
    55aa5f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions