From 27b3131422b53f9b37bba5235bc20610687fad2e Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 22 Sep 2024 12:00:51 +0200 Subject: [PATCH] Fix GH-15982: Assertion failure with array_find when references are involved Closes GH-15983. --- NEWS | 2 ++ ext/standard/array.c | 2 +- ext/standard/tests/array/gh15982.phpt | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/array/gh15982.phpt diff --git a/NEWS b/NEWS index 6e682cc3887..043bfb73300 100644 --- a/NEWS +++ b/NEWS @@ -51,6 +51,8 @@ PHP NEWS - Standard: . Add support for backed enums in http_build_query(). (ilutov) + . Fixed bug GH-15982 (Assertion failure with array_find when references are + involved). (nielsdos) - Zip: . Added ZipArchive::ER_TRUNCATED_ZIP added in libzip 1.11. (Remi) diff --git a/ext/standard/array.c b/ext/standard/array.c index a2fef8b1452..07ebd13e428 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -6628,7 +6628,7 @@ static zend_result php_array_find(const HashTable *array, zend_fcall_info fci, z if (retval_true) { if (result_value != NULL) { - ZVAL_COPY(result_value, &args[0]); + ZVAL_COPY_DEREF(result_value, &args[0]); } if (result_key != NULL) { diff --git a/ext/standard/tests/array/gh15982.phpt b/ext/standard/tests/array/gh15982.phpt new file mode 100644 index 00000000000..2eb9eceb231 --- /dev/null +++ b/ext/standard/tests/array/gh15982.phpt @@ -0,0 +1,11 @@ +--TEST-- +GH-15982 (Assertion failure with array_find when references are involved) +--FILE-- + true)); +?> +--EXPECT-- +string(5) "hello"