Commit f603ffb0fc0 for php

commit f603ffb0fc0250fe62b9ef1f29fa0166650323d6
Author: lacatoire <la.catoire@gmail.com>
Date:   Fri Nov 27 12:46:39 2026 +0800

    Fix iconv_mime_encode() overflowing on a negative line-length (#25485)

    Clamp a negative line-length to zero before converting it to size_t.
    This avoids a fatal allocation overflow and preserves the existing false
    return for a zero line-length without introducing a warning.

    Closes #25485

diff --git a/NEWS b/NEWS
index e12f3020190..d982a1008b1 100644
--- a/NEWS
+++ b/NEWS
@@ -98,6 +98,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 0212d1063c7..ca782de79a3 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 00000000000..76803bf471e
--- /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?="