From 92187d2e4e1980b31ff2aa174d7f917d0945e175 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 22 May 2026 11:18:15 +0200 Subject: sixel: clamp max width/height in 'CSI ? 2 ; 3 ; W ; H S' This ensures the user cannot raise the maximum sixel size, where width*height cannot be represented as an integer. Note, we should consider moving all sixel width/height variables from int to size_t. But, since it doesn't make any sense with overly large sixel images, clamping the max width/height is enough. Add a static_assert() that checks SIXEL_MAX_WIDTH * SIXEL_MAX_HEIGHT doesn't overflow. Closes #2343 --- sixel.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'sixel.c') diff --git a/sixel.c b/sixel.c index 187f1348..1db6336d 100644 --- a/sixel.c +++ b/sixel.c @@ -2207,9 +2207,11 @@ sixel_geometry_reset(struct terminal *term) void sixel_geometry_set(struct terminal *term, unsigned width, unsigned height) { - LOG_DBG("sixel geometry set to %ux%u", width, height); - term->sixel.max_width = width; - term->sixel.max_height = height; + const unsigned new_width = min(width, SIXEL_MAX_WIDTH); + const unsigned new_height = min(height, SIXEL_MAX_HEIGHT); + LOG_DBG("sixel geometry set to %ux%u", new_width, new_height); + term->sixel.max_width = new_width; + term->sixel.max_height = new_height; sixel_geometry_report_current(term); } -- cgit v1.3