Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Zend/tests/lazy_objects/gh20504-001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
GH-20504: Assertion failure in zend_get_property_guard() when lazy proxy adds magic method - isset
--CREDITS--
vi3tL0u1s
--FILE--
<?php

class RealInstance {
public $_;
}
class Proxy extends RealInstance {
public function __isset($name) {
return isset($this->$name['']);
}
}
$rc = new ReflectionClass(Proxy::class);
$obj = $rc->newLazyProxy(function () {
return new RealInstance;
});
var_dump(isset($obj->name['']));

?>
--EXPECT--
bool(false)
23 changes: 23 additions & 0 deletions Zend/tests/lazy_objects/gh20504-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
GH-20504: Assertion failure in zend_get_property_guard() when lazy proxy adds magic method - get
--FILE--
<?php

class RealInstance {
public $_;
}
class Proxy extends RealInstance {
public function __get($name) {
return $this->$name;
}
}
$rc = new ReflectionClass(Proxy::class);
$obj = $rc->newLazyProxy(function () {
return new RealInstance;
});
var_dump($obj->name);

?>
--EXPECTF--
Warning: Undefined property: RealInstance::$name in %s on line %d
NULL
33 changes: 33 additions & 0 deletions Zend/tests/lazy_objects/gh20504-003.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
GH-20504: Assertion failure in zend_get_property_guard() when lazy proxy adds magic method - set
--FILE--
<?php

#[AllowDynamicProperties]
class RealInstance {
public $_;
}
class Proxy extends RealInstance {
public function __set($name, $value) {
$this->$name = $value;
}
}
$rc = new ReflectionClass(Proxy::class);
$obj = $rc->newLazyProxy(function () {
return new RealInstance;
});
$obj->name = 0;

var_dump($obj);

?>
--EXPECTF--
lazy proxy object(Proxy)#%d (1) {
["instance"]=>
object(RealInstance)#%d (2) {
["_"]=>
NULL
["name"]=>
int(0)
}
}
28 changes: 28 additions & 0 deletions Zend/tests/lazy_objects/gh20504-004.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
GH-20504: Assertion failure in zend_get_property_guard() when lazy proxy adds magic method - proxy defines __isset(), both have guards
--FILE--
<?php

class RealInstance {
public $_;
public function __get($name) {
printf("%s::%s\n", static::class, __FUNCTION__);
}
}
class Proxy extends RealInstance {
public function __isset($name) {
printf("%s::%s\n", static::class, __FUNCTION__);
return isset($this->$name['']);
}
}
$rc = new ReflectionClass(Proxy::class);
$obj = $rc->newLazyProxy(function () {
return new RealInstance;
});
var_dump(isset($obj->name['']));

?>
--EXPECT--
Proxy::__isset
Proxy::__get
bool(false)
30 changes: 30 additions & 0 deletions Zend/tests/lazy_objects/gh20504-005.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
GH-20504: Assertion failure in zend_get_property_guard() when lazy proxy adds magic method - unset
--FILE--
<?php

class RealInstance {
public $_;
}
class Proxy extends RealInstance {
public function __unset($name) {
unset($this->$name);
}
}
$rc = new ReflectionClass(Proxy::class);
$obj = $rc->newLazyProxy(function () {
return new RealInstance;
});
unset($obj->name);

var_dump($obj);

?>
--EXPECTF--
lazy proxy object(Proxy)#%d (1) {
["instance"]=>
object(RealInstance)#%d (1) {
["_"]=>
NULL
}
}
16 changes: 8 additions & 8 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,25 +956,25 @@ ZEND_API zval *zend_std_read_property(zend_object *zobj, zend_string *name, int
uninit_error:
if (UNEXPECTED(zend_lazy_object_must_init(zobj))) {
if (!prop_info || (Z_PROP_FLAG_P(retval) & IS_PROP_LAZY)) {
zobj = zend_lazy_object_init(zobj);
if (!zobj) {
zend_object *instance = zend_lazy_object_init(zobj);
if (!instance) {
retval = &EG(uninitialized_zval);
goto exit;
}

if (UNEXPECTED(guard)) {
if (UNEXPECTED(guard && instance->ce->ce_flags & ZEND_ACC_USE_GUARDS)) {
uint32_t guard_type = (type == BP_VAR_IS) && zobj->ce->__isset
? IN_ISSET : IN_GET;
guard = zend_get_property_guard(zobj, name);
guard = zend_get_property_guard(instance, name);
if (!((*guard) & guard_type)) {
(*guard) |= guard_type;
retval = zend_std_read_property(zobj, name, type, cache_slot, rv);
retval = zend_std_read_property(instance, name, type, cache_slot, rv);
(*guard) &= ~guard_type;
return retval;
}
}

return zend_std_read_property(zobj, name, type, cache_slot, rv);
return zend_std_read_property(instance, name, type, cache_slot, rv);
}
}
if (type != BP_VAR_IS) {
Expand Down Expand Up @@ -1013,7 +1013,7 @@ static zval *forward_write_to_lazy_object(zend_object *zobj,
return &EG(error_zval);
}

if (UNEXPECTED(guarded)) {
if (UNEXPECTED(guarded && instance->ce->ce_flags & ZEND_ACC_USE_GUARDS)) {
uint32_t *guard = zend_get_property_guard(instance, name);
if (!((*guard) & IN_SET)) {
(*guard) |= IN_SET;
Expand Down Expand Up @@ -1597,7 +1597,7 @@ ZEND_API void zend_std_unset_property(zend_object *zobj, zend_string *name, void
return;
}

if (UNEXPECTED(guard)) {
if (UNEXPECTED(guard && zobj->ce->ce_flags & ZEND_ACC_USE_GUARDS)) {
guard = zend_get_property_guard(zobj, name);
if (!((*guard) & IN_UNSET)) {
(*guard) |= IN_UNSET;
Expand Down
Loading