From 1e81eea8990ca1e2370cde591a23e87c866d8000 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Tue, 29 Mar 2022 13:38:02 +0300 Subject: [PATCH] Input window: handle invalid multibyte MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current code enters an infinite loop if the input string happens to get an invalid utf-8 sequence somehow. For me it was reproducible by running profanity in a Screen session and pressing Alt-т (cyrillic letter). Fix it the way borrowed from 0501e49623f68aa39508e4e622924c1dd8147588 where mbrlen is used for the same purposes. --- src/ui/inputwin.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index d19d8719..ac7cf817 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -373,6 +373,10 @@ _inp_offset_to_col(char* str, int offset) while (i < offset && str[i] != '\0') { gunichar uni = g_utf8_get_char(&str[i]); size_t ch_len = mbrlen(&str[i], MB_CUR_MAX, NULL); + if ((ch_len == (size_t)-2) || (ch_len == (size_t)-1)) { + i++; + continue; + } i += ch_len; col++; if (g_unichar_iswide(uni)) {