From 731186f792e77c8355a6eee88556d8dd9a6c0700 Mon Sep 17 00:00:00 2001 From: Tomasz Kowalczyk Date: Wed, 25 Nov 2026 15:07:42 +0100 Subject: [PATCH] Fix GH-25746: array_column() crashes with JIT when the result for an empty array is modified Since 5d24c8bd605, array_column() returns the shared immutable empty array for an empty input. The stub still declared @refcount 1, which lets function JIT and tracing JIT modify the result in place and crash. Drop the annotation. --- NEWS | 2 ++ Zend/Optimizer/zend_func_infos.h | 1 - ext/standard/basic_functions.stub.php | 1 - ext/standard/basic_functions_arginfo.h | 2 +- ext/standard/basic_functions_decl.h | 8 ++++---- ext/standard/tests/array/gh25746.phpt | 24 ++++++++++++++++++++++++ 6 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 ext/standard/tests/array/gh25746.phpt diff --git a/NEWS b/NEWS index ea57424282cc..2fdef68c8ba3 100644 --- a/NEWS +++ b/NEWS @@ -241,6 +241,8 @@ PHP NEWS out-of-range width or height. (Ilia Alshanetsky) . Fixed JIT freeing the previous include_path returned by set_include_path() while it is still in use. (Ilia Alshanetsky) + . Fixed bug GH-25746 (array_column() crashes with JIT when the result for an + empty array is modified). (Tomasz Kowalczyk) - Streams: . Fixed in-place URL decoding of interned strings in the HTTP and FTP diff --git a/Zend/Optimizer/zend_func_infos.h b/Zend/Optimizer/zend_func_infos.h index 8a7bc2dfcf3f..d09d06318685 100644 --- a/Zend/Optimizer/zend_func_infos.h +++ b/Zend/Optimizer/zend_func_infos.h @@ -391,7 +391,6 @@ static const func_info_t func_infos[] = { FN("array_keys", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING), FN("array_values", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF), F1("array_count_values", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG), - F1("array_column", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF), F1("array_reverse", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF), F1("array_flip", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING), F1("array_change_key_case", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF), diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 2733e94468df..e354ee995b2c 100644 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -1741,7 +1741,6 @@ function array_count_values(array $array): array {} /** * @compile-time-eval - * @refcount 1 */ function array_column(array $array, int|string|null $column_key, int|string|null $index_key = null): array {} diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 9bc96ad43c65..163c26be4ad5 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit basic_functions.stub.php instead. - * Stub hash: cf186afde03090331d3037c23e49e75fe2670ff5 + * Stub hash: 3d3771e5df903f7c3e7f9dff8f66e63300e20709 * Has decl header: yes */ #include "zend_attributes.h" diff --git a/ext/standard/basic_functions_decl.h b/ext/standard/basic_functions_decl.h index ea0ca1d6f1ef..2a22968e8fbc 100644 --- a/ext/standard/basic_functions_decl.h +++ b/ext/standard/basic_functions_decl.h @@ -1,8 +1,8 @@ /* This is a generated file, edit basic_functions.stub.php instead. - * Stub hash: cf186afde03090331d3037c23e49e75fe2670ff5 */ + * Stub hash: 3d3771e5df903f7c3e7f9dff8f66e63300e20709 */ -#ifndef ZEND_BASIC_FUNCTIONS_DECL_cf186afde03090331d3037c23e49e75fe2670ff5_H -#define ZEND_BASIC_FUNCTIONS_DECL_cf186afde03090331d3037c23e49e75fe2670ff5_H +#ifndef ZEND_BASIC_FUNCTIONS_DECL_3d3771e5df903f7c3e7f9dff8f66e63300e20709_H +#define ZEND_BASIC_FUNCTIONS_DECL_3d3771e5df903f7c3e7f9dff8f66e63300e20709_H typedef enum zend_enum_SortDirection { ZEND_ENUM_SortDirection_Ascending = 1, @@ -20,4 +20,4 @@ typedef enum zend_enum_RoundingMode { ZEND_ENUM_RoundingMode_PositiveInfinity = 8, } zend_enum_RoundingMode; -#endif /* ZEND_BASIC_FUNCTIONS_DECL_cf186afde03090331d3037c23e49e75fe2670ff5_H */ +#endif /* ZEND_BASIC_FUNCTIONS_DECL_3d3771e5df903f7c3e7f9dff8f66e63300e20709_H */ diff --git a/ext/standard/tests/array/gh25746.phpt b/ext/standard/tests/array/gh25746.phpt new file mode 100644 index 000000000000..02d88576dfff --- /dev/null +++ b/ext/standard/tests/array/gh25746.phpt @@ -0,0 +1,24 @@ +--TEST-- +GH-25746: array_column() crashes with JIT when the result for an empty array is modified +--EXTENSIONS-- +opcache +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.jit=function +opcache.jit_buffer_size=64M +opcache.file_update_protection=0 +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + int(1) +}