diff options
author | Xinchen Hui <laruence@gmail.com> | 2018-06-21 17:26:05 +0800 |
---|---|---|
committer | Xinchen Hui <laruence@gmail.com> | 2018-06-21 17:26:05 +0800 |
commit | 6531719da575e8ceb14fa8e9fefcac2ab365dd00 (patch) | |
tree | aa6967ef5fc21ac9fce0a9dc4d341fa80466a926 | |
parent | bcf2e10ae75a02d35971d446f430eafd41e48db5 (diff) | |
download | php-git-6531719da575e8ceb14fa8e9fefcac2ab365dd00.tar.gz |
Fixed bug #76505 (array_merge_recursive() is duplicating sub-array keys)
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | ext/standard/array.c | 6 | ||||
-rw-r--r-- | ext/standard/tests/array/bug70808.phpt | 2 | ||||
-rw-r--r-- | ext/standard/tests/array/bug76505.phpt | 33 |
4 files changed, 39 insertions, 6 deletions
@@ -9,6 +9,10 @@ PHP NEWS . Fixed bug #73342 (Vulnerability in php-fpm by changing stdin to non-blocking). (Nikita) +- Standard: + . Fixed bug #76505 (array_merge_recursive() is duplicating sub-array keys). + (Laruence) + 22 Jun 2019, PHP 7.1.19 - CLI Server: diff --git a/ext/standard/array.c b/ext/standard/array.c index 183cf123c3..646ffad198 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2996,10 +2996,6 @@ 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 > (zend_long)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); } @@ -3032,7 +3028,7 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */ zval_add_ref(zv); } } else { - zval *zv = zend_hash_next_index_insert_new(dest, src_entry); + zval *zv = zend_hash_next_index_insert(dest, src_entry); zval_add_ref(zv); } } ZEND_HASH_FOREACH_END(); diff --git a/ext/standard/tests/array/bug70808.phpt b/ext/standard/tests/array/bug70808.phpt index 8a625386d3..df82da8c00 100644 --- a/ext/standard/tests/array/bug70808.phpt +++ b/ext/standard/tests/array/bug70808.phpt @@ -17,7 +17,7 @@ Array [key] => Array ( [0] => 0 - [1] => 2 + [2] => 2 ) ) diff --git a/ext/standard/tests/array/bug76505.phpt b/ext/standard/tests/array/bug76505.phpt new file mode 100644 index 0000000000..ad0b2c86e5 --- /dev/null +++ b/ext/standard/tests/array/bug76505.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #76505 (array_merge_recursive() is duplicating sub-array keys) +--FILE-- +<?php +$array1 = array( + 'k' => array( + 2 => 100, + 98 => 200, + ) +); + +$array2 = array( + 'k' => array( + 64 => 300 + ) +); + +$array3 = array_merge_recursive( $array1, $array2 ); + +var_dump($array3); +?> +--EXPECT-- +array(1) { + ["k"]=> + array(3) { + [2]=> + int(100) + [98]=> + int(200) + [99]=> + int(300) + } +} |