From c2404915e016c63c1873f588cbfeb0909a314e62 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Mon, 2 Jan 2023 15:34:03 +0100 Subject: [PATCH] Fix GH-10200: zif_get_object_vars: Assertion `!(((__ht)->u.flags & (1<<2)) != 0)' failed. This occurs because the array of properties is a single element with an integer key, not an associative array. Therefore it is a packed array and thus the assumption the iteration macro makes is invalid. This restores the behaviour of PHP<8.2. Closes GH-10209 Co-authored-by: Deltik Signed-off-by: George Peter Banyard --- NEWS | 4 ++++ Zend/tests/gh10200.phpt | 20 ++++++++++++++++++++ Zend/zend_builtin_functions.c | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/gh10200.phpt diff --git a/NEWS b/NEWS index 341af094271f5..ba9b1c1142d3c 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.2.2 +- Core: + . Fixed bug GH-10200 (zif_get_object_vars: + Assertion `!(((__ht)->u.flags & (1<<2)) != 0)' failed). (nielsdos) + - FPM: . Fixed bug #77106 (Missing separator in FPM FastCGI errors). (Jakub Zelenka) . Fixed bug GH-9981 (FPM does not reset fastcgi.error_header). diff --git a/Zend/tests/gh10200.phpt b/Zend/tests/gh10200.phpt new file mode 100644 index 0000000000000..5462352e7ae5b --- /dev/null +++ b/Zend/tests/gh10200.phpt @@ -0,0 +1,20 @@ +--TEST-- +GH-10200 (zif_get_object_vars: Assertion `!(((__ht)->u.flags & (1<<2)) != 0)' failed.) +--FILE-- + +https://github.com/php/php-src/issues/10200 not encountered +EOF; + +$xml = simplexml_load_string($xmlData); +$output = get_object_vars($xml); +var_dump($output); + +?> +--EXPECT-- +array(1) { + [0]=> + string(59) "https://github.com/php/php-src/issues/10200 not encountered" +} diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 8813fa9788a97..5cebbbc560894 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -760,7 +760,7 @@ ZEND_FUNCTION(get_object_vars) } else { array_init_size(return_value, zend_hash_num_elements(properties)); - ZEND_HASH_MAP_FOREACH_KEY_VAL(properties, num_key, key, value) { + ZEND_HASH_FOREACH_KEY_VAL(properties, num_key, key, value) { bool is_dynamic = 1; if (Z_TYPE_P(value) == IS_INDIRECT) { value = Z_INDIRECT_P(value);