From b4f92c4c2455bd81096f07c0b6dc8f4fa365a85c Mon Sep 17 00:00:00 2001 From: Tomasz Kowalczyk Date: Wed, 25 Nov 2026 22:44:45 +0100 Subject: [PATCH] Fix GH-25766: enchant_dict_suggest() crashes with JIT when the result for a word without suggestions is modified Since 5dd5a4267f8, enchant_dict_suggest() returns the shared immutable empty array for a word without suggestions. The stub still declared @refcount 1, which lets function JIT and tracing JIT modify the result in place and crash. Drop the annotation. --- NEWS | 4 ++++ Zend/Optimizer/zend_func_infos.h | 2 +- ext/enchant/enchant.stub.php | 1 - ext/enchant/enchant_arginfo.h | 2 +- ext/enchant/tests/gh25766.phpt | 28 ++++++++++++++++++++++++++++ 5 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 ext/enchant/tests/gh25766.phpt diff --git a/NEWS b/NEWS index 47b729fab04c..4b726ec2445f 100644 --- a/NEWS +++ b/NEWS @@ -76,6 +76,10 @@ PHP NEWS . Fixed use-after-free in getElementById() after a removed ID attribute is freed. (Ilia Alshanetsky) +- Enchant: + . Fixed bug GH-25766 (enchant_dict_suggest() crashes with JIT when the result + for a word without suggestions is modified). (Tomasz Kowalczyk) + - FFI: . Fixed bug GH-25558 (struct with an enum field passed by value is described to libffi with a void element). (Davide Peressoni) diff --git a/Zend/Optimizer/zend_func_infos.h b/Zend/Optimizer/zend_func_infos.h index 193e9e9b4c06..d76b7fec4047 100644 --- a/Zend/Optimizer/zend_func_infos.h +++ b/Zend/Optimizer/zend_func_infos.h @@ -85,7 +85,7 @@ static const func_info_t func_infos[] = { FN("dba_list", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING), F1("enchant_broker_list_dicts", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ARRAY), F1("enchant_broker_describe", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ARRAY), - F1("enchant_dict_suggest", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING), + FN("enchant_dict_suggest", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING), F1("enchant_dict_describe", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING), F1("exif_tagname", MAY_BE_STRING|MAY_BE_FALSE), F1("exif_read_data", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_FALSE), diff --git a/ext/enchant/enchant.stub.php b/ext/enchant/enchant.stub.php index 6ddbee768f14..cba8a8433f72 100644 --- a/ext/enchant/enchant.stub.php +++ b/ext/enchant/enchant.stub.php @@ -81,7 +81,6 @@ function enchant_dict_check(EnchantDictionary $dictionary, string $word): bool { /** * @return array - * @refcount 1 */ function enchant_dict_suggest(EnchantDictionary $dictionary, string $word): array {} diff --git a/ext/enchant/enchant_arginfo.h b/ext/enchant/enchant_arginfo.h index d60fe4dde0a1..f1c1d7c85592 100644 --- a/ext/enchant/enchant_arginfo.h +++ b/ext/enchant/enchant_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit enchant.stub.php instead. - * Stub hash: 31974eb901477da53ede7476953d461d32f772ba */ + * Stub hash: 9d4c55408db80a88d769eb52cd38ca732919cdf8 */ #include "zend_attributes.h" #include "zend_constants.h" diff --git a/ext/enchant/tests/gh25766.phpt b/ext/enchant/tests/gh25766.phpt new file mode 100644 index 000000000000..ec4b1ca9705b --- /dev/null +++ b/ext/enchant/tests/gh25766.phpt @@ -0,0 +1,28 @@ +--TEST-- +GH-25766: enchant_dict_suggest() crashes with JIT when the result for a word without suggestions is modified +--EXTENSIONS-- +enchant +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) +}