Skip to content

Commit da786a2

Browse files
committed
Fixed bug #79930
We're inserting src_zval, so that's what we should addref.
1 parent 12db8b9 commit da786a2

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ PHP NEWS
1717
. Fixed bug #73060 (php failed with error after temp folder cleaned up).
1818
(cmb)
1919

20+
- Standard:
21+
. Fixed bug #79930 (array_merge_recursive() crashes when called with array
22+
with single reference). (Nikita)
23+
2024
06 Aug 2020, PHP 7.3.21
2125

2226
- Apache:

ext/standard/array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3615,7 +3615,7 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */
36153615
return 0;
36163616
}
36173617
} else {
3618-
Z_TRY_ADDREF_P(src_entry);
3618+
Z_TRY_ADDREF_P(src_zval);
36193619
zend_hash_next_index_insert(Z_ARRVAL_P(dest_zval), src_zval);
36203620
}
36213621
zval_ptr_dtor(&tmp);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #79930: array_merge_recursive() crashes when called with array with single reference
3+
--FILE--
4+
<?php
5+
6+
$a = 'a';
7+
$array = [
8+
'value' => $a . 'b',
9+
];
10+
11+
// Create rc=1 reference.
12+
array_walk($array, function () {});
13+
14+
$m = array_merge_recursive(['value' => 'a'], $array);
15+
16+
var_dump($a, $array, $m);
17+
18+
?>
19+
--EXPECT--
20+
string(1) "a"
21+
array(1) {
22+
["value"]=>
23+
string(2) "ab"
24+
}
25+
array(1) {
26+
["value"]=>
27+
array(2) {
28+
[0]=>
29+
string(1) "a"
30+
[1]=>
31+
string(2) "ab"
32+
}
33+
}

0 commit comments

Comments
 (0)