Skip to content

Segmentation fault Zend/zend_hash.h:1629 #17200

Closed

Description

@YuanchengJiang

Description

The following code:

<?php
class A {
public $prop = 41;
}
class B extends A {
public $prop = 42 {
get {
}
}
}
$b = new B();
var_dump($b);
$fusion = $b;
$inputs =  array (
@$fusion,
);
foreach($inputs as $input) {
var_dump(json_encode($input));
}

Resulted in this output:

object(B)#1 (1) {
  ["prop"]=>
  int(42)
}
Zend/zend_hash.h:1629:20: runtime error: member access within misaligned address 0x0000000000b1 for type 'zend_string' (aka 'struct _zend_string'), which requires 8 byte alignment
0x0000000000b1: note: pointer points here
<memory cannot be printed>
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Zend/zend_hash.h:1629:20

PHP Version

nightly

Operating System

No response

Activity

  1. cmb69 commented on Dec 17, 2024

    @cmb69
    Member

    Slightly simplified reproducer:

    <?php
    class A {
        public $prop = 41;
    }
    class B extends A {
        public $prop = 42 {
            get {
            }
        }
    }
    $b = new B();
    var_dump($b);
    json_encode($b);

    Looks like both var_dump() and json_encode() are required to trigger this.

    Seems to be related to property hooks, so maybe @iluuu1994 will have a look.

  2. self-assigned this
    on Dec 17, 2024
  3. iluuu1994 commented on Dec 17, 2024

    @iluuu1994
    Member

    Good grief, how does this code still have bugs 😭 I'll have a look.

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