Skip to content

Commit 6531719

Browse files
committed
Fixed bug #76505 (array_merge_recursive() is duplicating sub-array keys)
1 parent bcf2e10 commit 6531719

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ PHP NEWS
99
. Fixed bug #73342 (Vulnerability in php-fpm by changing stdin to
1010
non-blocking). (Nikita)
1111

12+
- Standard:
13+
. Fixed bug #76505 (array_merge_recursive() is duplicating sub-array keys).
14+
(Laruence)
15+
1216
22 Jun 2019, PHP 7.1.19
1317

1418
- CLI Server:

ext/standard/array.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,10 +2996,6 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */
29962996
if (Z_TYPE_P(dest_zval) == IS_NULL) {
29972997
convert_to_array_ex(dest_zval);
29982998
add_next_index_null(dest_zval);
2999-
} else if (Z_TYPE_P(dest_zval) == IS_ARRAY) {
3000-
if (UNEXPECTED(Z_ARRVAL_P(dest_zval)->nNextFreeElement > (zend_long)Z_ARRVAL_P(dest_zval)->nNumUsed)) {
3001-
Z_ARRVAL_P(dest_zval)->nNextFreeElement = Z_ARRVAL_P(dest_zval)->nNumUsed;
3002-
}
30032999
} else {
30043000
convert_to_array_ex(dest_zval);
30053001
}
@@ -3032,7 +3028,7 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */
30323028
zval_add_ref(zv);
30333029
}
30343030
} else {
3035-
zval *zv = zend_hash_next_index_insert_new(dest, src_entry);
3031+
zval *zv = zend_hash_next_index_insert(dest, src_entry);
30363032
zval_add_ref(zv);
30373033
}
30383034
} ZEND_HASH_FOREACH_END();

ext/standard/tests/array/bug70808.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Array
1717
[key] => Array
1818
(
1919
[0] => 0
20-
[1] => 2
20+
[2] => 2
2121
)
2222

2323
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #76505 (array_merge_recursive() is duplicating sub-array keys)
3+
--FILE--
4+
<?php
5+
$array1 = array(
6+
'k' => array(
7+
2 => 100,
8+
98 => 200,
9+
)
10+
);
11+
12+
$array2 = array(
13+
'k' => array(
14+
64 => 300
15+
)
16+
);
17+
18+
$array3 = array_merge_recursive( $array1, $array2 );
19+
20+
var_dump($array3);
21+
?>
22+
--EXPECT--
23+
array(1) {
24+
["k"]=>
25+
array(3) {
26+
[2]=>
27+
int(100)
28+
[98]=>
29+
int(200)
30+
[99]=>
31+
int(300)
32+
}
33+
}

0 commit comments

Comments
 (0)