[php-src] master: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Fri, 27 Nov 2026 05:04:36 +0000
Subject: [php-src] master: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144248@lists.php.net to get a copy of this message
Author: Weilin Du (LamentXU123) Date: 2026-11-27T12:52:18+08:00 Commit: https://github.com/php/php-src/commit/2a407fb98f22d951a606b887404a20d6063633e9 Raw diff: https://github.com/php/php-src/commit/2a407fb98f22d951a606b887404a20d6063633e9.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: Fix iconv_mime_encode() overflowing on a negative line-length (#25485) Changed paths: A ext/iconv/tests/mime_encode_line_length_invalid.phpt M NEWS M ext/iconv/iconv.c Diff: diff --git a/NEWS b/NEWS index 5c7e85f81541..bf73fce0dd8a 100644 --- a/NEWS +++ b/NEWS @@ -90,6 +90,10 @@ PHP NEWS . Fixed hash() and hash_file() hanging on invalid xxh3/xxh128 options. (lacatoire) +- Iconv: + . Fixed iconv_mime_encode() failing with an integer overflow error for a + negative line-length. (lacatoire) + - Intl: . Fixed Locale::lookup() ignoring the default locale when the language tag list is empty. (Weilin Du) diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 2713e4cd70d5..0d1654e27e24 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -2087,6 +2087,9 @@ PHP_FUNCTION(iconv_mime_encode) if ((pzval = zend_hash_str_find_deref(Z_ARRVAL_P(pref), "line-length", sizeof("line-length") - 1)) != NULL) { line_len = zval_get_long(pzval); + if (line_len < 0) { + line_len = 0; + } } if ((pzval = zend_hash_str_find_deref(Z_ARRVAL_P(pref), "line-break-chars", sizeof("line-break-chars") - 1)) != NULL) { diff --git a/ext/iconv/tests/mime_encode_line_length_invalid.phpt b/ext/iconv/tests/mime_encode_line_length_invalid.phpt new file mode 100644 index 000000000000..76803bf471e1 --- /dev/null +++ b/ext/iconv/tests/mime_encode_line_length_invalid.phpt @@ -0,0 +1,22 @@ +--TEST-- +iconv_mime_encode(): a negative line-length behaves like 0 +--EXTENSIONS-- +iconv +--FILE-- +<?php +$o = ["input-charset" => "UTF-8", "output-charset" => "UTF-8"]; +foreach ([-1, 0, PHP_INT_MIN] as $len) { + var_dump(iconv_mime_encode("S", "héllo", $o + ["line-length" => $len])); +} +var_dump(iconv_mime_encode("S", "héllo", $o + ["line-length" => 76])); +?> +--EXPECTF-- +Warning: iconv_mime_encode(): Buffer length exceeded in %s on line %d +bool(false) + +Warning: iconv_mime_encode(): Buffer length exceeded in %s on line %d +bool(false) + +Warning: iconv_mime_encode(): Buffer length exceeded in %s on line %d +bool(false) +string(%d) "S: =?UTF-8?B?%s?="

« previous php.cvs (#144248) next »