We're inserting src_zval, so that's what we should addref.
This commit is contained in:
Nikita Popov 2020-08-05 15:41:42 +02:00
parent 12db8b90a7
commit da786a22af
3 changed files with 38 additions and 1 deletions

4
NEWS
View File

@ -17,6 +17,10 @@ PHP NEWS
. Fixed bug #73060 (php failed with error after temp folder cleaned up).
(cmb)
- Standard:
. Fixed bug #79930 (array_merge_recursive() crashes when called with array
with single reference). (Nikita)
06 Aug 2020, PHP 7.3.21
- Apache:

View File

@ -3615,7 +3615,7 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */
return 0;
}
} else {
Z_TRY_ADDREF_P(src_entry);
Z_TRY_ADDREF_P(src_zval);
zend_hash_next_index_insert(Z_ARRVAL_P(dest_zval), src_zval);
}
zval_ptr_dtor(&tmp);

View File

@ -0,0 +1,33 @@
--TEST--
Bug #79930: array_merge_recursive() crashes when called with array with single reference
--FILE--
<?php
$a = 'a';
$array = [
'value' => $a . 'b',
];
// Create rc=1 reference.
array_walk($array, function () {});
$m = array_merge_recursive(['value' => 'a'], $array);
var_dump($a, $array, $m);
?>
--EXPECT--
string(1) "a"
array(1) {
["value"]=>
string(2) "ab"
}
array(1) {
["value"]=>
array(2) {
[0]=>
string(1) "a"
[1]=>
string(2) "ab"
}
}