Skip to content

DOMXPath breaks when not initialized properly #16316

Closed
@DanielEScherzer

Description

@DanielEScherzer

Description

The following code:

<?php

class Demo extends DOMXPath {
    public function __construct() {}
    public function __debugInfo(): array {
        return ['x' => 'y'];
    }
}

var_dump( new Demo() );

Resulted in this output:

Segmentation fault

But I expected this output instead:

object(Demo)#1 (1) {
  ["x"]=>
  string(1) "y"
}
Valgrind
==23084== Invalid read of size 4
==23084==    at 0x45A7BB: php_dom_create_object (php_dom.c:1680)
==23084==    by 0x46976E: dom_xpath_document_read (xpath.c:181)
==23084==    by 0x454DBD: dom_get_debug_info_helper (php_dom.c:518)
==23084==    by 0x454E7E: dom_get_debug_info (php_dom.c:541)
==23084==    by 0x97868C: zend_std_get_properties_for (zend_object_handlers.c:2384)
==23084==    by 0x978826: zend_get_properties_for (zend_object_handlers.c:2433)
==23084==    by 0x73D66D: php_var_dump (var.c:178)
==23084==    by 0x73DC57: zif_var_dump (var.c:245)
==23084==    by 0x88D15C: ZEND_DO_ICALL_SPEC_RETVAL_UNUSED_HANDLER (zend_vm_execute.h:1287)
==23084==    by 0x909ACE: execute_ex (zend_vm_execute.h:58774)
==23084==    by 0x90E410: zend_execute (zend_vm_execute.h:64206)
==23084==    by 0x9A4E2B: zend_execute_script (zend.c:1928)
==23084==  Address 0x8 is not stack'd, malloc'd or (recently) free'd

PHP Version

PHP 8.4 dev (f2fbb75)

Operating System

No response

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