Skip to content

Commit 350ff53

Browse files
committed
Fix utf8_check_validity
index is already increased in the loop, so we should not over advance
1 parent 3b25b05 commit 350ff53

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

extension/android/jni/jni_layer_llama.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ bool utf8_check_validity(const char* str, size_t length) {
4242
uint8_t next_byte = static_cast<uint8_t>(str[i + 1]);
4343
if ((byte & 0xE0) == 0xC0 &&
4444
(next_byte & 0xC0) == 0x80) { // 2-byte sequence
45-
i += 2;
45+
i += 1;
4646
} else if (
4747
(byte & 0xF0) == 0xE0 && (next_byte & 0xC0) == 0x80 &&
4848
(i + 2 < length) &&
4949
(static_cast<uint8_t>(str[i + 2]) & 0xC0) ==
5050
0x80) { // 3-byte sequence
51-
i += 3;
51+
i += 2;
5252
} else if (
5353
(byte & 0xF8) == 0xF0 && (next_byte & 0xC0) == 0x80 &&
5454
(i + 2 < length) &&
5555
(static_cast<uint8_t>(str[i + 2]) & 0xC0) == 0x80 &&
5656
(i + 3 < length) &&
5757
(static_cast<uint8_t>(str[i + 3]) & 0xC0) ==
5858
0x80) { // 4-byte sequence
59-
i += 4;
59+
i += 3;
6060
} else {
6161
return false; // Invalid sequence
6262
}

0 commit comments

Comments
 (0)