From 817adf5bfccedaa70267127c6981c142c82243b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 30 Aug 2022 00:37:30 +0200 Subject: [PATCH] Fix order of dynamic/readonly property checks --- ext/spl/spl_fixedarray.c | 3 +++ ext/standard/var_unserializer.re | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 14b8e9ab467de..472759338270a 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -629,6 +629,9 @@ PHP_METHOD(SplFixedArray, __unserialize) if (intern->array.size == 0) { size = zend_hash_num_elements(data); spl_fixedarray_init_non_empty_struct(&intern->array, size); + if (!size) { + return; + } array_init(&members_zv); intern->array.size = 0; diff --git a/ext/standard/var_unserializer.re b/ext/standard/var_unserializer.re index 8d49cb75a7446..72d50c190e653 100644 --- a/ext/standard/var_unserializer.re +++ b/ext/standard/var_unserializer.re @@ -641,6 +641,18 @@ declared_property: int ret = is_property_visibility_changed(obj->ce, &key); if (EXPECTED(!ret)) { + if (UNEXPECTED(obj->ce->ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES)) { + zend_throw_error(NULL, "Cannot create dynamic property %s::$%s", + ZSTR_VAL(obj->ce->name), zend_get_unmangled_property_name(Z_STR_P(&key))); + goto failure; + } else if (!(obj->ce->ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES)) { + zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated", + ZSTR_VAL(obj->ce->name), zend_get_unmangled_property_name(Z_STR_P(&key))); + if (EG(exception)) { + goto failure; + } + } + data = zend_hash_add_new(ht, Z_STR(key), &EG(uninitialized_zval)); } else if (ret < 0) { goto failure; @@ -654,18 +666,6 @@ second_try: ZVAL_NULL(data); } } - - if (UNEXPECTED(obj->ce->ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES)) { - zend_throw_error(NULL, "Cannot create dynamic property %s::$%s", - ZSTR_VAL(obj->ce->name), zend_get_unmangled_property_name(Z_STR_P(&key))); - goto failure; - } else if (!(obj->ce->ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES)) { - zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated", - ZSTR_VAL(obj->ce->name), zend_get_unmangled_property_name(Z_STR_P(&key))); - if (EG(exception)) { - goto failure; - } - } } zval_ptr_dtor_str(&key); } else if (Z_TYPE(key) == IS_LONG) {