com php-src: Fixed bug #70808 (array_merge_recursive co rrupts memory of unset items): ext/standard/array .c ext/standard/tests/array/bug70808.phpt
| From: | Anatol Belski | Date: | Sun, 08 Nov 2015 01:17:20 +0000 |
| Subject: | com php-src: Fixed bug #70808 (array_merge_recursive co rrupts memory of unset items): ext/standard/array .c ext/standard/tests/array/bug70808.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-89704@lists.php.net to get a copy of this message | ||
Commit: 51f9948b2bcfb7b33f6739b13b88957c063be9a6
Author: Xinchen Hui <laruence@gmail.com> Thu, 29 Oct 2015 14:33:58 +0800
Committer: Anatol Belski <ab@php.net> Sun, 8 Nov 2015 02:17:20 +0100
Parents: ae79c52c123f4ce04a82873bf2f14a8335f8f34a
Branches: PHP-7.0.0
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=51f9948b2bcfb7b33f6739b13b88957c063be9a6
Log:
Fixed bug #70808 (array_merge_recursive corrupts memory of unset items)
I knew, this fix seems ugly
Bugs:
https://bugs.php.net/70808
Changed paths:
M ext/standard/array.c
A ext/standard/tests/array/bug70808.phpt
Diff:
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 4678e14..88818fe 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -2967,6 +2967,10 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{
*/
if (Z_TYPE_P(dest_zval) == IS_NULL) {
convert_to_array_ex(dest_zval);
add_next_index_null(dest_zval);
+ } else if (Z_TYPE_P(dest_zval) == IS_ARRAY) {
+ if (UNEXPECTED(Z_ARRVAL_P(dest_zval)->nNextFreeElement >
Z_ARRVAL_P(dest_zval)->nNumUsed)) {
+ Z_ARRVAL_P(dest_zval)->nNextFreeElement = Z_ARRVAL_P(dest_zval)->nNumUsed;
+ }
} else {
convert_to_array_ex(dest_zval);
}
diff --git a/ext/standard/tests/array/bug70808.phpt b/ext/standard/tests/array/bug70808.phpt
new file mode 100644
index 0000000..8a62538
--- /dev/null
+++ b/ext/standard/tests/array/bug70808.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Bug #70808 (array_merge_recursive corrupts memory of unset items)
+--FILE--
+<?php
+
+$arr1 = array("key" => array(0, 1));
+$arr2 = array("key" => array(2));
+
+unset($arr1["key"][1]);
+
+$result = array_merge_recursive($arr1, $arr2);
+print_r($result);
+?>
+--EXPECT--
+Array
+(
+ [key] => Array
+ (
+ [0] => 0
+ [1] => 2
+ )
+
+)