From 2efdd2583da9575242091bb53c57a311c3eacbc6 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Fri, 12 Sep 2025 15:44:14 +0300 Subject: kms++util: Fix drawing outside fb boundaries Signed-off-by: Tomi Valkeinen --- kms++util/src/colorbar.cpp | 7 +++++++ kms++util/src/drawing.cpp | 4 ++++ 2 files changed, 11 insertions(+) (limited to 'kms++util') diff --git a/kms++util/src/colorbar.cpp b/kms++util/src/colorbar.cpp index cd0b978..c727306 100644 --- a/kms++util/src/colorbar.cpp +++ b/kms++util/src/colorbar.cpp @@ -99,6 +99,13 @@ static void drm_draw_color_bar_semiplanar_yuv(IFramebuffer& buf, int old_xpos, i void draw_color_bar(IFramebuffer& buf, int old_xpos, int xpos, int width) { + // Skip if the bar is not fully drawable + if (xpos + width > (int)buf.width()) + return; + + if (old_xpos >= 0 && old_xpos + width > (int)buf.width()) + old_xpos = -1; + switch (buf.format()) { case PixelFormat::NV12: case PixelFormat::NV21: diff --git a/kms++util/src/drawing.cpp b/kms++util/src/drawing.cpp index 862638b..7e3ca97 100644 --- a/kms++util/src/drawing.cpp +++ b/kms++util/src/drawing.cpp @@ -533,6 +533,10 @@ static bool get_char_pixel(char c, uint32_t x, uint32_t y) static void draw_char(IFramebuffer& buf, uint32_t xpos, uint32_t ypos, char c, RGB color) { + // Skip characters that are not fully drawable + if (xpos + 8 > buf.width() || ypos + 8 > buf.height()) + return; + unsigned x, y; YUV yuvcolor = color.yuv(); -- cgit v1.2.3