From 1ebdc0116263c2ac8f5b4de98c8bfe0aa768480b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 3 May 2020 11:27:06 +0200 Subject: [PATCH] unicode-combining: detect when we've reached the chain limit We currently store up to 5 combining characters in any given base+combining chain. This adds a check for when that limit is about to be exceeded. When this happens, we log the chain + the new combining character. Since things will break anyway, we simply overwrite the last combining character. --- vt.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vt.c b/vt.c index 74110eb6..4ceaa25b 100644 --- a/vt.c +++ b/vt.c @@ -641,6 +641,20 @@ action_utf8_print(struct terminal *term, uint8_t c) #endif size_t wanted_count = composed != NULL ? composed->count + 1 : 1; + if (wanted_count > ALEN(composed->combining)) { + assert(composed != NULL); + + LOG_WARN("combining character overflow:"); + LOG_WARN(" base: 0x%04x", composed->base); + for (size_t i = 0; i < composed->count; i++) + LOG_WARN(" cc: 0x%04x", composed->combining[i]); + LOG_ERR(" new: 0x%04x", wc); + + /* This are going to break anyway... */ + wanted_count--; + } + + assert(wanted_count <= ALEN(composed->combining)); /* Look for existing combining chain */ for (size_t i = 0; i < term->composed_count; i++) {