fix: custom spell-checker stuck in infinite loop (#45019)

`ReadUnicodeCharacter` updates index to the last character read, and not after it. We need to manually increment it to move to the next character.

It also doesn't validate that the index is valid, so we need to check that index is within bounds.

Refs: #44336

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Jesper Ek <deadbeef84@gmail.com>
This commit is contained in:
trop[bot] 2024-12-16 09:55:20 +01:00 committed by GitHub
parent 5c6d6c1d5e
commit 0702ed0212
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -31,7 +31,9 @@ namespace {
bool HasWordCharacters(const std::u16string& text, size_t index) {
base_icu::UChar32 code;
while (base::ReadUnicodeCharacter(text.c_str(), text.size(), &index, &code)) {
while (index < text.size() &&
base::ReadUnicodeCharacter(text.c_str(), text.size(), &index, &code)) {
++index;
UErrorCode error = U_ZERO_ERROR;
if (uscript_getScript(code, &error) != USCRIPT_COMMON)
return true;