Commit c36abbc6dee for php
commit c36abbc6dee1c578f6b59224ba3f246686df6b29
Author: Ilia Alshanetsky <ilia@ilia.ws>
Date: Thu Nov 19 08:01:01 2026 -0500
ext/gettext: Fix refcount info for gettext(), dgettext(), dcgettext()
These functions return the msgid argument itself when there is no
translation, so a non-interned msgid comes back with a refcount above 1.
Their stubs claimed @refcount 1, which let the function and tracing JIT
release the result without checking the refcount and free a string the
caller still holds. Drop the annotation. The other gettext functions
return a new string or false and keep the annotation.
Fixes GH-25584
Closes GH-25593
diff --git a/NEWS b/NEWS
index 992b0318b9e..2415ca123f7 100644
--- a/NEWS
+++ b/NEWS
@@ -59,6 +59,10 @@ PHP NEWS
. Fixed the argument blamed by the imagepolygon(), imageopenpolygon() and
imagefilledpolygon() too few points error. (lacatoire)
+- Gettext:
+ . Fixed bug GH-25584 (JIT frees the string returned by gettext(),
+ dgettext() or dcgettext() while it is still in use). (Ilia Alshanetsky)
+
- Intl:
. Fixed Locale::lookup() ignoring the default locale when the language tag
list is empty. (Weilin Du)
diff --git a/Zend/Optimizer/zend_func_infos.h b/Zend/Optimizer/zend_func_infos.h
index df175ea0a5f..7006bd6c815 100644
--- a/Zend/Optimizer/zend_func_infos.h
+++ b/Zend/Optimizer/zend_func_infos.h
@@ -146,9 +146,6 @@ static const func_info_t func_infos[] = {
F1("imageaffinematrixconcat", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_DOUBLE|MAY_BE_FALSE),
F1("imageresolution", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_TRUE),
F1("textdomain", MAY_BE_STRING),
- F1("gettext", MAY_BE_STRING),
- F1("dgettext", MAY_BE_STRING),
- F1("dcgettext", MAY_BE_STRING),
F1("bindtextdomain", MAY_BE_STRING|MAY_BE_FALSE),
#if defined(HAVE_NGETTEXT)
F1("ngettext", MAY_BE_STRING),
diff --git a/ext/gettext/gettext.stub.php b/ext/gettext/gettext.stub.php
index 3e9a50177a5..7b89dabb7c4 100644
--- a/ext/gettext/gettext.stub.php
+++ b/ext/gettext/gettext.stub.php
@@ -5,16 +5,13 @@
/** @refcount 1 */
function textdomain(?string $domain = null): string {}
-/** @refcount 1 */
function gettext(string $message): string {}
/** @alias gettext */
function _(string $message): string {}
-/** @refcount 1 */
function dgettext(string $domain, string $message): string {}
-/** @refcount 1 */
function dcgettext(string $domain, string $message, int $category): string {}
/** @refcount 1 */
diff --git a/ext/gettext/gettext_arginfo.h b/ext/gettext/gettext_arginfo.h
index 265f6cd900e..a0eb8e2657c 100644
Binary files a/ext/gettext/gettext_arginfo.h and b/ext/gettext/gettext_arginfo.h differ
diff --git a/ext/gettext/tests/gh25584.phpt b/ext/gettext/tests/gh25584.phpt
new file mode 100644
index 00000000000..f9fbe4f2a0b
--- /dev/null
+++ b/ext/gettext/tests/gh25584.phpt
@@ -0,0 +1,22 @@
+--TEST--
+GH-25584 (JIT frees the string returned by gettext(), dgettext() and dcgettext() while still referenced)
+--EXTENSIONS--
+gettext
+opcache
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.jit=function
+opcache.jit_buffer_size=64M
+opcache.file_update_protection=0
+--FILE--
+<?php
+$s = str_repeat("a", mt_rand(3, 3));
+gettext($s);
+dgettext("x", $s);
+dcgettext("x", $s, LC_CTYPE);
+echo "msgid after calls: ";
+var_dump($s);
+?>
+--EXPECT--
+msgid after calls: string(3) "aaa"