diff --git a/Zend/tests/oss-fuzz-471486164-001.phpt b/Zend/tests/oss-fuzz-471486164-001.phpt new file mode 100644 index 000000000000..a48a56398c1e --- /dev/null +++ b/Zend/tests/oss-fuzz-471486164-001.phpt @@ -0,0 +1,22 @@ +--TEST-- +OSS-Fuzz #471486164: get_property_ptr_ptr() on uninitialized hooked property +--FILE-- + $this->a; + set { $this->a = &$value; } + } + public $x = 1; +} + +$proxy = (new ReflectionClass(C::class))->newLazyProxy(function ($proxy) { + $proxy->a = 1; + return new C; +}); +var_dump($proxy->x); + +?> +--EXPECT-- +int(1) diff --git a/Zend/tests/oss-fuzz-471486164-002.phpt b/Zend/tests/oss-fuzz-471486164-002.phpt new file mode 100644 index 000000000000..688dd7612201 --- /dev/null +++ b/Zend/tests/oss-fuzz-471486164-002.phpt @@ -0,0 +1,26 @@ +--TEST-- +OSS-Fuzz #471486164: get_property_ptr_ptr() on uninitialized hooked property +--FILE-- + $this->a; + set { + global $ref; + $this->a = &$ref; + } + } +} + +$ref = 1; +$proxy = new C; +$proxy->a = 1; +var_dump($proxy->a); +$ref++; +var_dump($proxy->a); + +?> +--EXPECT-- +int(1) +int(2) diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index c113f65a7a89..ccedb79acc08 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -1392,6 +1392,7 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam property_offset = zend_get_property_offset(zobj->ce, name, (zobj->ce->__get != NULL), cache_slot, &prop_info); if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) { +try_again: retval = OBJ_PROP(zobj, property_offset); if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) { if (EXPECTED(!zobj->ce->__get) || @@ -1471,7 +1472,15 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam } retval = zend_hash_add(zobj->properties, name, &EG(uninitialized_zval)); } - } else if (!IS_HOOKED_PROPERTY_OFFSET(property_offset) && zobj->ce->__get == NULL) { + } else if (IS_HOOKED_PROPERTY_OFFSET(property_offset)) { + if (!(prop_info->flags & ZEND_ACC_VIRTUAL) && !zend_should_call_hook(prop_info, zobj)) { + property_offset = prop_info->offset; + if (!ZEND_TYPE_IS_SET(prop_info->type)) { + prop_info = NULL; + } + goto try_again; + } + } else if (zobj->ce->__get == NULL) { retval = &EG(error_zval); }