From 0ccd092c0f5ac236a26fcebe8a1e1f662bccb0c7 Mon Sep 17 00:00:00 2001 From: chenkeyu Date: Wed, 7 Aug 2024 17:39:37 +0800 Subject: [PATCH] =?UTF-8?q?check=20utf8Len=20to=20prevent=20add=20overflow?= =?UTF-8?q?=20=EF=BC=88cherry=20picked=20commit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/src/string_ex.cpp | 2 +- base/src/unicode_ex.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/base/src/string_ex.cpp b/base/src/string_ex.cpp index f54e7bf..eb56b0d 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 c21e39e..ff455be 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; } -- Gitee