mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-08 22:33:17 +00:00
Debug Tools: fixed DebugTextEncoding() potentially reading out of bounds if provided a trailing truncated UTF-8 sequence.
This commit is contained in:
11
imgui.cpp
11
imgui.cpp
@@ -1642,14 +1642,15 @@ void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c)
|
||||
AddInputCharacter((unsigned)cp);
|
||||
}
|
||||
|
||||
void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
|
||||
void ImGuiIO::AddInputCharactersUTF8(const char* str)
|
||||
{
|
||||
if (!AppAcceptingEvents)
|
||||
return;
|
||||
while (*utf8_chars != 0)
|
||||
const char* str_end = str + strlen(str);
|
||||
while (*str != 0)
|
||||
{
|
||||
unsigned int c = 0;
|
||||
utf8_chars += ImTextCharFromUtf8(&c, utf8_chars, NULL);
|
||||
str += ImTextCharFromUtf8(&c, str, str_end);
|
||||
AddInputCharacter(c);
|
||||
}
|
||||
}
|
||||
@@ -2502,6 +2503,7 @@ int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char*
|
||||
int len = lengths[*(const unsigned char*)in_text >> 3];
|
||||
int wanted = len + (len ? 0 : 1);
|
||||
|
||||
// IMPORTANT: if in_text_end == NULL it assume we have enough space!
|
||||
if (in_text_end == NULL)
|
||||
in_text_end = in_text + wanted; // Max length, nulls will be taken into account.
|
||||
|
||||
@@ -15998,10 +16000,11 @@ void ImGui::DebugTextEncoding(const char* str)
|
||||
TableSetupColumn("Glyph");
|
||||
TableSetupColumn("Codepoint");
|
||||
TableHeadersRow();
|
||||
const char* str_end = str + strlen(str); // As we may receive malformed UTF-8, pass an explicit end instead of relying on ImTextCharFromUtf8() assuming enough space.
|
||||
for (const char* p = str; *p != 0; )
|
||||
{
|
||||
unsigned int c;
|
||||
const int c_utf8_len = ImTextCharFromUtf8(&c, p, NULL);
|
||||
const int c_utf8_len = ImTextCharFromUtf8(&c, p, str_end);
|
||||
TableNextColumn();
|
||||
Text("%d", (int)(p - str));
|
||||
TableNextColumn();
|
||||
|
||||
Reference in New Issue
Block a user