string.c: avoid infinite loop; fix #6143

`mrb_utf8len` returns 0 for invalid characters.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-01-09 10:19:37 +09:00
parent a5e83075d4
commit 64a4bf0e28
+4 -1
View File
@@ -409,7 +409,10 @@ str_index_str_by_char_search(mrb_state *mrb, const char *p, const char *pend, co
if (pivot >= pend || pivot < p /* overflowed */) { return -1; }
do {
p += mrb_utf8len(p, pend);
mrb_int len = mrb_utf8len(p, pend);
if (len == 0) p++; /* invalid character */
else p += len;
off++;
} while (p < pivot);
}