Filter out invalid chars to avoid out-of-bounds memory access

This commit is contained in:
Raphael Coeffic
2021-05-08 00:22:58 +02:00
parent edd9e2e287
commit 6a08317dde
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -58,7 +58,7 @@ int getTextWidth(const char * s, int len, LcdFlags flags)
if (!c) {
break;
}
else if (c >= 0xFE) {
else if (c >= 0xFE) { // CJK marker
s++;
c = uint8_t(*s) + ((c & 0x01) << 8) - 1;
if (c >= 0x101)
@@ -66,7 +66,7 @@ int getTextWidth(const char * s, int len, LcdFlags flags)
c += CJK_FIRST_LETTER_INDEX;
result += getFontPatternWidth(specs, c) + 1;
}
else if (c >= 0x20) {
else if ((c >= 0x20) && (c < CJK_FIRST_LETTER_INDEX + 0x20)) { // debug
result += getCharWidth(c, specs);
}