Skip to content

Commit

Permalink
fix: custom spell-checker stuck in infinite loop (electron#45001)
Browse files Browse the repository at this point in the history
`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: electron#44336
  • Loading branch information
deadbeef84 authored Dec 13, 2024
1 parent be1a3dc commit e2e7150
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion shell/renderer/api/electron_api_spell_check_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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;
Expand Down

0 comments on commit e2e7150

Please sign in to comment.