From ef4cbee1277fe6a630054222d16efacc59715ebc Mon Sep 17 00:00:00 2001 From: nirenjan Date: Sun, 8 Mar 2026 19:56:33 -0700 Subject: [PATCH] fix: Handle malformed UTF-8 input in libx52util The libx52util_convert_utf8_string function manually converts the UTF-8 string into the character map supported by the X52/X52Pro MFD. However, there was a bug when handling malformed UTF-8 input. If the state machine thinks it is at the start of a word and receives malformed UTF-8 input (between 0x80 and 0xC0), it will ignore the characters, but it will not reset the entry to the map_root location, thereby causing subsequent characters to be dropped. This change ensures that the entry is reset to map_root[*input] after skipping over an invalid UTF-8 sequence. --- libx52util/x52_char_map_lookup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libx52util/x52_char_map_lookup.c b/libx52util/x52_char_map_lookup.c index 016f136..6dcd450 100644 --- a/libx52util/x52_char_map_lookup.c +++ b/libx52util/x52_char_map_lookup.c @@ -75,10 +75,12 @@ int libx52util_convert_utf8_string(const uint8_t *input, while (*input >= 0x80 && *input < 0xC0) { input++; /* Skip invalid characters */ } + + /* New UTF-8 character, reset the entry pointer */ + entry = &map_root[*input]; } } *len = index; return retval; } -