Commit 7170f7b2dd0 for php
commit 7170f7b2dd0ef1221a925571f620f4e30aef6e8b
Author: Tomasz Kowalczyk <tomasz@kowalczyk.cc>
Date: Sun Nov 29 20:39:05 2026 +0100
Fix GH-25766: enchant_dict_suggest() crashes with JIT when the result for a word without suggestions is modified (#25767)
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.
diff --git a/NEWS b/NEWS
index c9834106400..70376b2d44f 100644
--- a/NEWS
+++ b/NEWS
@@ -88,6 +88,10 @@ PHP NEWS
. Fixed bug GH-25750 (adoptNode() accepts DTD declaration nodes, which can
crash at document teardown). (Ian Mattas)
+- 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 49c546b9ca6..bccc934827d 100644
--- a/Zend/Optimizer/zend_func_infos.h
+++ b/Zend/Optimizer/zend_func_infos.h
@@ -84,7 +84,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 6ddbee768f1..cba8a8433f7 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<int, string>
- * @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 d60fe4dde0a..f1c1d7c8559 100644
Binary files a/ext/enchant/enchant_arginfo.h and b/ext/enchant/enchant_arginfo.h differ
diff --git a/ext/enchant/tests/gh25766.phpt b/ext/enchant/tests/gh25766.phpt
new file mode 100644
index 00000000000..ec4b1ca9705
--- /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--
+<?php
+function test(EnchantDictionary $dictionary, string $word) {
+ $suggestions = enchant_dict_suggest($dictionary, $word);
+ $suggestions[] = 1;
+ return $suggestions;
+}
+
+$broker = enchant_broker_init();
+$dictionary = enchant_broker_request_pwl_dict($broker, __DIR__ . "/enchant_broker_request_pwl_dict.pwl");
+var_dump(test($dictionary, "zzzzzzzzzzzz"));
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ int(1)
+}