Skip to content

Segmentation fault (access null pointer) in ext/dom/parentnode/tree.c #16039

Closed

Description

@YuanchengJiang

Description

The following code:

<?php
$entity = new DOMEntity();
$fusion = $entity;
$dom = new DOMDocument;
$element = $dom->appendChild($dom->createElement('root'));
$str = str_repeat('X', 2**31 + 10);
try {
$element->append('x', $str);
} catch (ValueError $e) {
$element->prepend('x', $fusion);
}

Resulted in this output:

/php-src/ext/dom/parentnode/tree.c:245:12: runtime error: member access within null pointer of type 'xmlNode' (aka 'struct _xmlNode')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /php-src/ext/dom/parentnode/tree.c:245

To reproduce:

-d "memory_limit=-1"

PHP Version

PHP 8.4.0-dev

Operating System

ubuntu 22.04

Activity

  1. DanielEScherzer commented on Sep 25, 2024

    @DanielEScherzer
    Member

    Minimal reproduction:

    <?php
    $dom = new DOMDocument;
    $element = $dom->appendChild($dom->createElement('root'));
    $str = str_repeat('X', 2**31 + 10);
    try {
        $element->append('x', $str);
    } catch (ValueError $e) {
        $element->prepend('x', new DOMEntity());
    }
  2. ndossche commented on Sep 25, 2024

    @ndossche
    Member

    Very old bug, must've been here since the beginning that DOMParentNode was here.

  3. added 4 commits that reference this issue on Sep 25, 2024
    555d240
    043b9e1
    68d494d
    9754674
  4. added a commit that references this issue on Sep 25, 2024
    0d1d905
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions