From 6057160dbf1d34584383621c197943f3f2219545 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Mon, 16 Jun 2003 17:35:16 +0000 Subject: [PATCH] Fixed bug #24198 (Invalid recursion detection in array_merge_recurcive()) --- ext/standard/array.c | 2 +- ext/standard/tests/array/bug24198.phpt | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/array/bug24198.phpt diff --git a/ext/standard/array.c b/ext/standard/array.c index b6ec420ccb..909b97f011 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2141,7 +2141,7 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS case HASH_KEY_IS_STRING: if (recursive && zend_hash_find(dest, string_key, string_key_len, (void **)&dest_entry) == SUCCESS) { - if (*src_entry == *dest_entry) { + if (*src_entry == *dest_entry && ((*dest_entry)->refcount % 2)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected"); return 0; } diff --git a/ext/standard/tests/array/bug24198.phpt b/ext/standard/tests/array/bug24198.phpt new file mode 100644 index 0000000000..b1cd523026 --- /dev/null +++ b/ext/standard/tests/array/bug24198.phpt @@ -0,0 +1,25 @@ +--TEST--n +Bug #24198 (array_merge_recursive() invalid recursion detection) +--FILE-- + 'aa','b' => 'bb'); + +var_dump(array_merge_recursive($c, $c)); +?> +--EXPECT-- +array(2) { + ["a"]=> + array(2) { + [0]=> + string(2) "aa" + [1]=> + string(2) "aa" + } + ["b"]=> + array(2) { + [0]=> + string(2) "bb" + [1]=> + string(2) "bb" + } +} -- 2.40.0