Fixed an issue where corrupt Unicode strings could crash the application.

This commit is contained in:
Leon Styhre 2021-12-14 17:08:37 +01:00
parent b04c6d88a9
commit 5fd2c86c7d

View file

@ -306,7 +306,7 @@ namespace Utils
result = (stringArg[cursor++]); result = (stringArg[cursor++]);
} }
// 11110xxx, four byte character. // 11110xxx, four byte character.
else if (checkCharType >= 0xF0) { else if (checkCharType >= 0xF0 && cursor < stringArg.length() - 2) {
// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
result = (stringArg[cursor++] & 0x07) << 18; result = (stringArg[cursor++] & 0x07) << 18;
result |= (stringArg[cursor++] & 0x3F) << 12; result |= (stringArg[cursor++] & 0x3F) << 12;
@ -314,14 +314,14 @@ namespace Utils
result |= stringArg[cursor++] & 0x3F; result |= stringArg[cursor++] & 0x3F;
} }
// 1110xxxx, three byte character. // 1110xxxx, three byte character.
else if (checkCharType >= 0xE0) { else if (checkCharType >= 0xE0 && cursor < stringArg.length() - 1) {
// 1110xxxx 10xxxxxx 10xxxxxx // 1110xxxx 10xxxxxx 10xxxxxx
result = (stringArg[cursor++] & 0x0F) << 12; result = (stringArg[cursor++] & 0x0F) << 12;
result |= (stringArg[cursor++] & 0x3F) << 6; result |= (stringArg[cursor++] & 0x3F) << 6;
result |= stringArg[cursor++] & 0x3F; result |= stringArg[cursor++] & 0x3F;
} }
// 110xxxxx, two byte character. // 110xxxxx, two byte character.
else if (checkCharType >= 0xC0) { else if (checkCharType >= 0xC0 && cursor < stringArg.length()) {
// 110xxxxx 10xxxxxx // 110xxxxx 10xxxxxx
result = (stringArg[cursor++] & 0x1F) << 6; result = (stringArg[cursor++] & 0x1F) << 6;
result |= stringArg[cursor++] & 0x3F; result |= stringArg[cursor++] & 0x3F;