php-src icon indicating copy to clipboard operation
php-src copied to clipboard

misaligned zval read in zho_build_properties_ex: hooked property in a subclass of an internal class with virtual properties

Open YuanchengJiang opened this issue 3 weeks ago • 0 comments

Description

The following code:

<?php
class Test extends DOMDocument {
    public int $prop { set => $value; }
}
$doc = new Test;
var_dump(get_object_vars($doc));

Resulted in this output:

Zend/zend_types.h:697:13: runtime error: member access within misaligned address 0x7f5c86875167 for type 'const zval' (aka 'const struct _zval_struct'), which requires 8 byte alignment
0x7f5c86875167: note: pointer points here
<memory cannot be printed>
    #0 0x6ae2022 in zval_get_type Zend/zend_types.h:697:13
    #1 0x6adf4b2 in zho_build_properties_ex Zend/zend_property_hooks.c:101:9
    #2 0x6addcbf in zend_hooked_object_build_properties Zend/zend_property_hooks.c:140:9
    #3 0x6a0de7e in zend_std_get_properties_for Zend/zend_object_handlers.c:2653:12
    #4 0x6a0e931 in zend_get_properties_for Zend/zend_object_handlers.c:2691:9
    #5 0x5d133e7 in zif_get_object_vars Zend/zend_builtin_functions.c:852:15
    #6 0x63f2cfb in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER Zend/zend_vm_execute.h:1393:2
    #7 0x5fabacc in execute_ex Zend/zend_vm_execute.h:110621:12
    #8 0x5fad941 in zend_execute Zend/zend_vm_execute.h:116059:2
    #9 0x6b9a226 in zend_execute_script Zend/zend.c:1980:3
    #10 0x550f6d6 in php_execute_script_ex main/main.c:2636:13
    #11 0x5510358 in php_execute_script main/main.c:2676:9
    #12 0x6bab555 in do_cli sapi/cli/php_cli.c:943:5
    #13 0x6ba61e7 in do_php_cli sapi/cli/php_cli.c:1360:18
    ...

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Zend/zend_types.h:697:13 in 

To reproduce: ./sapi/cli/php test.php

Found by https://github.com/php/flowfusion

PHP Version

nightly

Operating System

No response

YuanchengJiang avatar Nov 07 '26 09:11 YuanchengJiang