From 4956a91fcbc31dd618ffd88efd740170ee92c61a Mon Sep 17 00:00:00 2001 From: Tomasz Kowalczyk Date: Fri, 27 Nov 2026 10:38:30 +0100 Subject: [PATCH] Fix GH-25832: mb_encode_mimeheader() rejects null for $charset and $transfer_encoding The stub declares both parameters as ?string and the function treats a null $charset as "use the mail charset of the current language", but 29b02bf290c parsed them with Z_PARAM_STR when it replaced "s|S!s!sl". So null was deprecated and coerced to "", which is not a valid $charset, and it threw a TypeError with strict_types. Parse both with Z_PARAM_STR_OR_NULL again. --- NEWS | 2 ++ ext/mbstring/mbstring.c | 4 ++-- ext/mbstring/tests/gh25832.phpt | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 ext/mbstring/tests/gh25832.phpt diff --git a/NEWS b/NEWS index d982a1008b1d..c254093716ab 100644 --- a/NEWS +++ b/NEWS @@ -119,6 +119,8 @@ PHP NEWS deeply nested arrays. (Eyüp Can Akman) . Fixed the JIT freeing the string returned by mb_encode_mimeheader() or mb_output_handler() while it is still in use. (Ilia Alshanetsky) + . Fixed bug GH-25832 (mb_encode_mimeheader() rejects null for $charset and + $transfer_encoding). (Tomasz Kowalczyk) - MySQLi: . Fixed bug GH-25779 (mysqli_fetch_object() crashes with JIT when the diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 3df3367de07c..4cd9de204cf5 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -6604,8 +6604,8 @@ PHP_FUNCTION(mb_encode_mimeheader) ZEND_PARSE_PARAMETERS_START(1, 5) Z_PARAM_STR(str) Z_PARAM_OPTIONAL - Z_PARAM_STR(charset_name) - Z_PARAM_STR(transenc_name) + Z_PARAM_STR_OR_NULL(charset_name) + Z_PARAM_STR_OR_NULL(transenc_name) Z_PARAM_STRING(linefeed, linefeed_len) Z_PARAM_LONG(indent) ZEND_PARSE_PARAMETERS_END(); diff --git a/ext/mbstring/tests/gh25832.phpt b/ext/mbstring/tests/gh25832.phpt new file mode 100644 index 000000000000..865fd9888bbc --- /dev/null +++ b/ext/mbstring/tests/gh25832.phpt @@ -0,0 +1,19 @@ +--TEST-- +GH-25832: mb_encode_mimeheader() rejects null for $charset and $transfer_encoding +--EXTENSIONS-- +mbstring +--FILE-- + +--EXPECT-- +string(20) "abc =?UTF-8?B?w6k=?=" +string(20) "abc =?UTF-8?B?w6k=?=" +string(20) "abc =?UTF-8?B?w6k=?=" +string(24) "abc =?ISO-8859-1?Q?=E9?="