From 56bcf04c496f5df1599f41e6bfd35a9a6b9a1ffc Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 23 Apr 2021 23:24:47 -0700 Subject: [PATCH] Debugger: Try harder to validate UTF-8. When sending this in the websocket debugger, it needs to be valid utf-8 or it will cause clients to abort the connection. We want to reject invalid utf-8 anyway. --- Core/Debugger/DisassemblyManager.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Core/Debugger/DisassemblyManager.cpp b/Core/Debugger/DisassemblyManager.cpp index d950fb5357..40daa83fef 100644 --- a/Core/Debugger/DisassemblyManager.cpp +++ b/Core/Debugger/DisassemblyManager.cpp @@ -64,13 +64,23 @@ bool IsLikelyStringAt(uint32_t addr) { if (utf.end()) return false; + char verify[4]; while (!utf.end()) { if (utf.invalid()) return false; + int pos = utf.byteIndex(); uint32_t c = utf.next(); + int len = UTF8::encode(verify, c); + // Our decoder is a bit lax, so let's verify this is a normal encoding. + // This prevents us from trying to output invalid encodings in the debugger. + if (memcmp(p + pos, verify, len) != 0 || pos + len != utf.byteIndex()) + return false; + if (c < ARRAY_SIZE(validControl) && !validControl[c]) return false; + if (c > 0x0010FFFF) + return false; } return true;