Skip to content

Commit 3d3b22d

Browse files
committed
Fix assertion failure in zend_std_read_property
We asserted that Z_PROP_FLAG_P(retval) was exactly IS_PROP_UNINIT, but this is a bit field and it may contain irrelevant bits. For instance it may contain IS_PROP_REINITABLE during clone, or IS_PROP_LAZY if the object is lazy. Fixes phpGH-16615 Closes phpGH-16639
1 parent ef56241 commit 3d3b22d

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ PHP NEWS
77
(nielsdos)
88
. Fixed bug GH-16577 (EG(strtod_state).freelist leaks with opcache.preload).
99
(nielsdos)
10+
. Fixed bug GH-16615 (Assertion failure in zend_std_read_property). (Arnaud)
1011

1112
- DOM:
1213
. Fixed bug GH-16594 (Assertion failure in DOM -> before). (nielsdos)

Zend/tests/gh16615_001.phpt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-16615 001 (Assertion failure in zend_std_read_property)
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public string $bar {
8+
set => $value;
9+
}
10+
}
11+
12+
$reflector = new ReflectionClass(Foo::class);
13+
14+
// Adds IS_PROP_LAZY to prop flags
15+
$foo = $reflector->newLazyGhost(function ($ghost) {
16+
$ghost->bar = 'bar';
17+
});
18+
19+
echo $foo->bar;
20+
21+
?>
22+
--EXPECT--
23+
bar

Zend/tests/gh16615_002.phpt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GH-16615 002 (Assertion failure in zend_std_read_property)
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public string $bar {
8+
set => $value;
9+
}
10+
public function __clone() {
11+
try {
12+
echo $this->bar;
13+
} catch (Error $e) {
14+
printf("%s: %s\n", $e::class, $e->getMessage());
15+
}
16+
}
17+
}
18+
19+
// Adds IS_PROP_REINITABLE to prop flags
20+
clone new Foo();
21+
22+
?>
23+
--EXPECT--
24+
Error: Typed property Foo::$bar must not be accessed before initialization

Zend/zend_object_handlers.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ ZEND_API zval *zend_std_read_property(zend_object *zobj, zend_string *name, int
791791
if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
792792
/* As hooked properties can't be unset, the only way to end up with an undef
793793
* value is via an uninitialized property. */
794-
ZEND_ASSERT(Z_PROP_FLAG_P(retval) == IS_PROP_UNINIT);
794+
ZEND_ASSERT(Z_PROP_FLAG_P(retval) & IS_PROP_UNINIT);
795795
goto uninit_error;
796796
}
797797

0 commit comments

Comments
 (0)