mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-11 00:04:24 +00:00
Debug Tools: fixed DebugTextEncoding() potentially reading out of bounds if provided a trailing truncated UTF-8 sequence.
This commit is contained in:
parent
2a194e21a0
commit
8df962a6ed
4 changed files with 14 additions and 7 deletions
|
|
@ -64,6 +64,8 @@ Other Changes:
|
||||||
triggered by some widgets e.g. Checkbox(), Selectable() and many others, which
|
triggered by some widgets e.g. Checkbox(), Selectable() and many others, which
|
||||||
cleared ActiveId at the same time as editing. (#9028)
|
cleared ActiveId at the same time as editing. (#9028)
|
||||||
Note that IsItemDeactivatedAfterEdit() was not affected, only IsItemEdited).
|
Note that IsItemDeactivatedAfterEdit() was not affected, only IsItemEdited).
|
||||||
|
- Debug Tools: fixed DebugTextEncoding() potentially reading out of bounds
|
||||||
|
if provided a trailing truncated UTF-8 sequence.
|
||||||
- Backends:
|
- Backends:
|
||||||
- GLFW: fixed building on Linux platforms where Wayland headers
|
- GLFW: fixed building on Linux platforms where Wayland headers
|
||||||
are not available. (#9024, #8969, #8921, #8920) [@jagot]
|
are not available. (#9024, #8969, #8921, #8920) [@jagot]
|
||||||
|
|
@ -78,7 +80,6 @@ Other Changes:
|
||||||
(note: examples application were not updated yet)
|
(note: examples application were not updated yet)
|
||||||
- Win32: Revert 1.92.4 change of comparing dwPacketNumber, which prevents
|
- Win32: Revert 1.92.4 change of comparing dwPacketNumber, which prevents
|
||||||
refreshing accurate gamepad info after focus-out + io.ClearInputKeys(). (#8556)
|
refreshing accurate gamepad info after focus-out + io.ClearInputKeys(). (#8556)
|
||||||
|
|
||||||
- Examples:
|
- Examples:
|
||||||
- GLFW+WebGPU: removed unnecessary ImGui_ImplWGPU_InvalidateDeviceObjects() call
|
- GLFW+WebGPU: removed unnecessary ImGui_ImplWGPU_InvalidateDeviceObjects() call
|
||||||
during surface resize. (#8381)
|
during surface resize. (#8381)
|
||||||
|
|
|
||||||
11
imgui.cpp
11
imgui.cpp
|
|
@ -1642,14 +1642,15 @@ void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c)
|
||||||
AddInputCharacter((unsigned)cp);
|
AddInputCharacter((unsigned)cp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
|
void ImGuiIO::AddInputCharactersUTF8(const char* str)
|
||||||
{
|
{
|
||||||
if (!AppAcceptingEvents)
|
if (!AppAcceptingEvents)
|
||||||
return;
|
return;
|
||||||
while (*utf8_chars != 0)
|
const char* str_end = str + strlen(str);
|
||||||
|
while (*str != 0)
|
||||||
{
|
{
|
||||||
unsigned int c = 0;
|
unsigned int c = 0;
|
||||||
utf8_chars += ImTextCharFromUtf8(&c, utf8_chars, NULL);
|
str += ImTextCharFromUtf8(&c, str, str_end);
|
||||||
AddInputCharacter(c);
|
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 len = lengths[*(const unsigned char*)in_text >> 3];
|
||||||
int wanted = len + (len ? 0 : 1);
|
int wanted = len + (len ? 0 : 1);
|
||||||
|
|
||||||
|
// IMPORTANT: if in_text_end == NULL it assume we have enough space!
|
||||||
if (in_text_end == NULL)
|
if (in_text_end == NULL)
|
||||||
in_text_end = in_text + wanted; // Max length, nulls will be taken into account.
|
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("Glyph");
|
||||||
TableSetupColumn("Codepoint");
|
TableSetupColumn("Codepoint");
|
||||||
TableHeadersRow();
|
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; )
|
for (const char* p = str; *p != 0; )
|
||||||
{
|
{
|
||||||
unsigned int c;
|
unsigned int c;
|
||||||
const int c_utf8_len = ImTextCharFromUtf8(&c, p, NULL);
|
const int c_utf8_len = ImTextCharFromUtf8(&c, p, str_end);
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
Text("%d", (int)(p - str));
|
Text("%d", (int)(p - str));
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
|
|
|
||||||
|
|
@ -5023,7 +5023,9 @@ const ImWchar* ImFontAtlas::GetGlyphRangesVietnamese()
|
||||||
|
|
||||||
void ImFontGlyphRangesBuilder::AddText(const char* text, const char* text_end)
|
void ImFontGlyphRangesBuilder::AddText(const char* text, const char* text_end)
|
||||||
{
|
{
|
||||||
while (text_end ? (text < text_end) : *text)
|
if (text_end == NULL)
|
||||||
|
text_end = text + strlen(text);
|
||||||
|
while (text < text_end)
|
||||||
{
|
{
|
||||||
unsigned int c = 0;
|
unsigned int c = 0;
|
||||||
int c_len = ImTextCharFromUtf8(&c, text, text_end);
|
int c_len = ImTextCharFromUtf8(&c, text, text_end);
|
||||||
|
|
|
||||||
|
|
@ -5151,12 +5151,13 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||||
{
|
{
|
||||||
// Filter pasted buffer
|
// Filter pasted buffer
|
||||||
const int clipboard_len = (int)ImStrlen(clipboard);
|
const int clipboard_len = (int)ImStrlen(clipboard);
|
||||||
|
const char* clipboard_end = clipboard + clipboard_len;
|
||||||
ImVector<char> clipboard_filtered;
|
ImVector<char> clipboard_filtered;
|
||||||
clipboard_filtered.reserve(clipboard_len + 1);
|
clipboard_filtered.reserve(clipboard_len + 1);
|
||||||
for (const char* s = clipboard; *s != 0; )
|
for (const char* s = clipboard; *s != 0; )
|
||||||
{
|
{
|
||||||
unsigned int c;
|
unsigned int c;
|
||||||
int in_len = ImTextCharFromUtf8(&c, s, NULL);
|
int in_len = ImTextCharFromUtf8(&c, s, clipboard_end);
|
||||||
s += in_len;
|
s += in_len;
|
||||||
if (!InputTextFilterCharacter(&g, &c, flags, callback, callback_user_data, true))
|
if (!InputTextFilterCharacter(&g, &c, flags, callback, callback_user_data, true))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue