From 69663666c13050ecb9b31867f9de61aa8d81ce55 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 12 Mar 2008 19:13:00 +0000 Subject: [PATCH] Fixed bug #42177 (Warning "array_merge_recursive(): recursion detected" comes again...) --- NEWS | 2 ++ ext/standard/array.c | 2 +- ext/standard/tests/array/bug42177.phpt | 34 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/array/bug42177.phpt diff --git a/NEWS b/NEWS index 924aa482e7..da2e4996b4 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ PHP NEWS - Fixed bug #44394 (Last two bytes missing from output). (Felipe) - Fixed bug #44388 (Crash inside exif_read_data() on invalid images) (Ilia) - Fixed bug #44373 (PDO_OCI extension compile failed). (Felipe) +- Fixed bug #42177 (Warning "array_merge_recursive(): recursion detected" comes + again...). (Felipe) 06 Mar 2008, PHP 5.2.6RC2 - Fixed bug #44333 (SEGFAULT when using mysql_pconnect() with client_flags). diff --git a/ext/standard/array.c b/ext/standard/array.c index 2dbfa0e035..664ee6ccdc 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2305,7 +2305,7 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS if (recursive && zend_hash_find(dest, string_key, string_key_len, (void **)&dest_entry) == SUCCESS) { HashTable *thash = HASH_OF(*dest_entry); - if ((thash && thash->nApplyCount > 1) || (*src_entry == *dest_entry && ((*dest_entry)->refcount % 2))) { + if ((thash && thash->nApplyCount > 1) || (*src_entry == *dest_entry && (*dest_entry)->is_ref && ((*dest_entry)->refcount % 2))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected"); return 0; } diff --git a/ext/standard/tests/array/bug42177.phpt b/ext/standard/tests/array/bug42177.phpt new file mode 100644 index 0000000000..5678ca3cac --- /dev/null +++ b/ext/standard/tests/array/bug42177.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #42177 (Warning "array_merge_recursive(): recursion detected" comes again...) +--FILE-- + 1, 'key3' => 2 ); +$a2 = array(); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +$a1 = array(); +$a2 = array( 'key1' => 1, 'key3' => 2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +$a1 = array(); +$a2 = array( 'key1' => &$a1 ); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +$x = 'foo'; +$y =& $x; +$a1 = array($x, $y, $x, $y); +$a2 = array( 'key1' => $a1, $x, $y ); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +?> +--EXPECTF-- +Warning: array_merge_recursive(): recursion detected in %s on line 18 -- 2.40.0