diff --git a/base/src/string_ex.cpp b/base/src/string_ex.cpp index f54e7bf263c6d48d6dfef2175dd804c4d5ed640b..eb56b0d0e060cbd3002c6ada24624eec4827a1e3 100644 --- a/base/src/string_ex.cpp +++ b/base/src/string_ex.cpp @@ -297,7 +297,7 @@ int Char16ToChar8(const u16string& str16, char *buffer, int bufferLen) } const char16_t *utf16Str = str16.c_str(); int utf8Len = Utf16ToUtf8Length(utf16Str, str16Len); - if (utf8Len < 0 || (utf8Len + 1) > bufferLen) { + if (utf8Len < 0 || utf8Len >= INT_MAX || (utf8Len + 1) > bufferLen) { UTILS_LOGD("utf8buffer len:%{public}d, actual buffer len:%{public}d!", utf8Len + 1, bufferLen); return CHAR16_TO_CHAR8_INSUFFICIENT_BUFFER; } diff --git a/base/src/unicode_ex.cpp b/base/src/unicode_ex.cpp index c21e39ee861d1f39bb714c473703218298a4f4e7..ff455be6a3cabc317b30aa4f09ccab57980e372a 100644 --- a/base/src/unicode_ex.cpp +++ b/base/src/unicode_ex.cpp @@ -181,7 +181,7 @@ char* Char16ToChar8(const char16_t* str16, size_t str16Len) { char* str8 = nullptr; int utf8Len = Utf16ToUtf8Length(str16, str16Len); - if (utf8Len < 0) { + if (utf8Len < 0 || utf8Len >= INT_MAX) { return nullptr; }