From 7b9484212231eb964acced22766a9db7be52354c Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 15 Jan 2026 18:47:43 -0500 Subject: [PATCH] ICUCtypeData: Fix MB_CUR_MAX under most encodings. See inline comment. Fixes #19881. --- src/system/libroot/add-ons/icu/ICUCtypeData.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/system/libroot/add-ons/icu/ICUCtypeData.cpp b/src/system/libroot/add-ons/icu/ICUCtypeData.cpp index 1a6018e0e6..4b7b1e839a 100644 --- a/src/system/libroot/add-ons/icu/ICUCtypeData.cpp +++ b/src/system/libroot/add-ons/icu/ICUCtypeData.cpp @@ -74,7 +74,14 @@ ICUCtypeData::SetTo(const Locale& locale, const char* posixLocaleName) ucnv_reset(converter); - *fDataBridge->addrOfMbCurMax = ucnv_getMaxCharSize(converter); + short mbMax = ucnv_getMaxCharSize(converter); + if (mbMax > 1 && mbMax < 4) { + // ucnv_getMaxCharSize() returns the maximum size of an encoded UChar, + // which is 16-bit, and not a 32-bit Unicode codepoint. So, unless + // some exotic encoding is being used, 4 is the value we actually want. + mbMax = 4; + } + *fDataBridge->addrOfMbCurMax = mbMax; char buffer[] = { 0, 0 }; for (int i = 0; i < 256; ++i) {