1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-21 05:53:02 +01:00

Prevent invalid access in malformed objects

This commit is contained in:
Michał Janiszewski
2016-12-26 23:42:19 +01:00
committed by Ted John
parent c3035b7601
commit 3aa0eb9bcd
6 changed files with 18 additions and 19 deletions

View File

@@ -142,12 +142,12 @@ static wchar_t convert_specific_language_character_to_unicode(int languageId, wc
}
}
static utf8 * convert_multibyte_charset(const char * src, int languageId)
static utf8 * convert_multibyte_charset(const char * src, size_t srcMaxSize, int languageId)
{
constexpr char CODEPOINT_DOUBLEBYTE = (char)0xFF;
auto sb = StringBuilder(64);
for (const char * ch = src; *ch != 0;)
for (const char * ch = src; (ch < src + srcMaxSize) && (*ch != 0);)
{
if (*ch == CODEPOINT_DOUBLEBYTE)
{
@@ -181,15 +181,15 @@ static bool rct2_language_is_multibyte_charset(int languageId)
}
}
utf8 *rct2_language_string_to_utf8(const char *src, int languageId)
utf8 *rct2_language_string_to_utf8(const char *src, size_t srcSize, int languageId)
{
if (rct2_language_is_multibyte_charset(languageId))
{
return convert_multibyte_charset(src, languageId);
return convert_multibyte_charset(src, srcSize, languageId);
}
else
{
return win1252_to_utf8_alloc(src);
return win1252_to_utf8_alloc(src, srcSize);
}
}