瀏覽代碼

Guard UTF-8 lookahead at string terminator

SybexXx 3 天之前
父節點
當前提交
efb1463620
共有 1 個文件被更改,包括 2 次插入 和 2 次删除
  1. 2 2
      code/main/server_main.cpp

+ 2 - 2
code/main/server_main.cpp

@@ -173,8 +173,8 @@ private:
                 {
                 {
                     // Preserve valid UTF-8; replace malformed bytes so the JSON remains parseable.
                     // Preserve valid UTF-8; replace malformed bytes so the JSON remains parseable.
                     const unsigned char b1 = cursor[1];
                     const unsigned char b1 = cursor[1];
-                    const unsigned char b2 = cursor[2];
-                    const unsigned char b3 = cursor[3];
+                    const unsigned char b2 = (b1 != 0) ? cursor[2] : 0;
+                    const unsigned char b3 = (b2 != 0) ? cursor[3] : 0;
                     size_t n = 0;
                     size_t n = 0;
                     if (*cursor >= 0xC2 && *cursor <= 0xDF && b1 >= 0x80 && b1 <= 0xBF) n = 2;
                     if (*cursor >= 0xC2 && *cursor <= 0xDF && b1 >= 0x80 && b1 <= 0xBF) n = 2;
                     else if (*cursor == 0xE0 && b1 >= 0xA0 && b1 <= 0xBF && b2 >= 0x80 && b2 <= 0xBF) n = 3;
                     else if (*cursor == 0xE0 && b1 >= 0xA0 && b1 <= 0xBF && b2 >= 0x80 && b2 <= 0xBF) n = 3;