iliaa Wed Dec 5 19:55:32 2007 UTC
Added files: (Branch: PHP_5_3)
/php-src/ext/standard/tests/array bug43495.phpt
Modified files:
/php-src/ext/standard array.c
Log:
Fixed bug #43495 (array_merge_recursive() crashes with recursive arrays)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/array.c?r1=1.308.2.21.2.37.2.10&r2=1.308.2.21.2.37.2.11&diff_format=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.308.2.21.2.37.2.10
php-src/ext/standard/array.c:1.308.2.21.2.37.2.11
--- php-src/ext/standard/array.c:1.308.2.21.2.37.2.10 Mon Dec 3 14:13:27 2007
+++ php-src/ext/standard/array.c Wed Dec 5 19:55:31 2007
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: array.c,v 1.308.2.21.2.37.2.10 2007/12/03 14:13:27 iliaa Exp $ */
+/* $Id: array.c,v 1.308.2.21.2.37.2.11 2007/12/05 19:55:31 iliaa Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -2191,7 +2191,9 @@
switch (zend_hash_get_current_key_ex(src, &string_key,
&string_key_len, &num_key, 0, &pos)) {
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 &&
(Z_REFCOUNT_PP(dest_entry) % 2)) {
+ HashTable *thash = HASH_OF(*dest_entry);
+
+ if ((thash && thash->nApplyCount > 1)
|| (*src_entry == *dest_entry && (Z_REFCOUNT_PP(dest_entry) % 2))) {
php_error_docref(NULL
TSRMLS_CC, E_WARNING, "recursion detected");
return 0;
}
@@ -2200,9 +2202,18 @@
convert_to_array_ex(dest_entry);
convert_to_array_ex(src_entry);
+ if (thash) {
+ thash->nApplyCount++;
+ }
if
(!php_array_merge(Z_ARRVAL_PP(dest_entry), Z_ARRVAL_PP(src_entry), recursive
TSRMLS_CC)) {
+ if (thash) {
+ thash->nApplyCount--;
+ }
return 0;
}
+ if (thash) {
+ thash->nApplyCount--;
+ }
} else {
Z_ADDREF_PP(src_entry);
zend_hash_update(dest, string_key,
string_key_len, src_entry, sizeof(zval *), NULL);
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/bug43495.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/bug43495.phpt
+++ php-src/ext/standard/tests/array/bug43495.phpt
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php