Commit 9a7d17ca983 for php

commit 9a7d17ca983e846e8ceba441ad37cf4a71bef0fc
Author: lazerg <lazerg2@gmail.com>
Date:   Sun Dec 6 17:38:37 2026 +0500

    ext/mbstring: Fix stale buffer pointer in mb_wchar_to_uuencode()

    mb_wchar_to_uuencode() grows the output buffer with MB_CONVERT_BUF_ENSURE(),
    which can move it, but the empty final call corner case then did buf->out--
    on the old pointer and returned. buf->str ended up in the new block while
    buf->out still pointed into the freed one, so mb_decode_mimeheader() got a
    garbage length and wrote the NUL through the stale pointer. Store the local
    out/limit on the early return like the normal exit path does.

    Fixes GH-26110
    Closes GH-26112

diff --git a/NEWS b/NEWS
index 8ba3ccdbef8..62fed60730c 100644
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,10 @@ PHP                                                                        NEWS
   . Fixed bug GH-26082 (IntlDatePatternGenerator crash with an invalid locale
     on ICU 70). (br1p4v3s1)

+- MBString:
+  . Fixed bug GH-26110 (mb_decode_mimeheader() with internal encoding UUENCODE
+    returns a string with a wrong length). (lazerg, joemax-o360)
+
 - ODBC:
   . Fixed bug GH-26053 (Odbc\Result not freed when its last reference is
     dropped). (merrillh, Ilia Alshanetsky)
diff --git a/ext/mbstring/libmbfl/filters/mbfilter_uuencode.c b/ext/mbstring/libmbfl/filters/mbfilter_uuencode.c
index 600d019b9d4..f982a0ea9cf 100644
--- a/ext/mbstring/libmbfl/filters/mbfilter_uuencode.c
+++ b/ext/mbstring/libmbfl/filters/mbfilter_uuencode.c
@@ -273,7 +273,7 @@ static void mb_wchar_to_uuencode(uint32_t *in, size_t len, mb_convert_buf *buf,
 		/* Corner case: under EXTREMELY rare circumstances, it's possible that the
 		 * final call to this conversion function will happen with an empty input
 		 * buffer, leaving an unwanted trailing len byte in the output buffer. */
-		buf->out--;
+		MB_CONVERT_BUF_STORE(buf, out - 1, limit);
 		return;
 	} else {
 		/* UUEncode starts each line with a byte which indicates how many bytes
diff --git a/ext/mbstring/tests/gh26110.phpt b/ext/mbstring/tests/gh26110.phpt
new file mode 100644
index 00000000000..72524240fc7
--- /dev/null
+++ b/ext/mbstring/tests/gh26110.phpt
@@ -0,0 +1,14 @@
+--TEST--
+GH-26110 (mb_decode_mimeheader() with internal encoding UUENCODE returns a string with a wrong length)
+--EXTENSIONS--
+mbstring
+--CREDITS--
+joemax-o360
+--FILE--
+<?php
+mb_internal_encoding("UUENCODE");
+$s = "\x89\xa3\x97\x9e\x8d\x8c\x9a\x8b\xc2\x00\xff\xff\x00\nG\n\x00\x9f\nK\x00\n\x9fs/\x00\x00\x00\xff\xff\x00\x87G\x00\n\x9f\nK\x00\n\x9f";
+var_dump(strlen(mb_decode_mimeheader($s)));
+?>
+--EXPECT--
+int(82)