[php-src] PHP-8.4: ext/gettext: Fix refcount info for gettext(), dgettext(), dcgettext()
| From: | Ilia Alshanetsky | Date: | Thu, 19 Nov 2026 23:29:34 +0000 |
| Subject: | [php-src] PHP-8.4: ext/gettext: Fix refcount info for gettext(), dgettext(), dcgettext() | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143937@lists.php.net to get a copy of this message | ||
Author: Ilia Alshanetsky (iliaal)
Date: 2026-11-19T18:17:30-05:00
Commit: https://github.com/php/php-src/commit/c36abbc6dee1c578f6b59224ba3f246686df6b29
Raw diff: https://github.com/php/php-src/commit/c36abbc6dee1c578f6b59224ba3f246686df6b29.diff
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
Changed paths:
A ext/gettext/tests/gh25584.phpt
M NEWS
M Zend/Optimizer/zend_func_infos.h
M ext/gettext/gettext.stub.php
M ext/gettext/gettext_arginfo.h
Diff:
diff --git a/NEWS b/NEWS
index 992b0318b9eb..2415ca123f7f 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 df175ea0a5fb..7006bd6c8156 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 3e9a50177a59..7b89dabb7c41 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 265f6cd900ed..a0eb8e2657cb 100644
--- a/ext/gettext/gettext_arginfo.h
+++ b/ext/gettext/gettext_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: c675dc9492943bbac106c5906b75c31436964423 */
+ * Stub hash: d2e9b8df0156e5b9f7e87f1b963530021d95d5f2 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_textdomain, 0, 0, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, domain, IS_STRING, 1, "null")
diff --git a/ext/gettext/tests/gh25584.phpt b/ext/gettext/tests/gh25584.phpt
new file mode 100644
index 000000000000..f9fbe4f2a0b3
--- /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"