From 901cc51a8c394829caa50059d498ab5b8b4a57cf Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 20 Nov 2026 09:35:39 +0800 Subject: [PATCH] buffer: Discard pixels with negative coordinates DrawTarget implementations must silently discard out-of-bounds pixels. draw_iter only checked the upper bounds, so a negative coordinate was cast to a huge usize: with y < 0 the index is out of range and the unwrap() panics (panic = abort hangs the boot); with x < 0 the index wraps into the previous row in release builds, or panics on overflow in debug builds. Not reachable with the current fixed layout, but any element drawn partly off-screen (e.g. a wider text box) would trigger it. Signed-off-by: Daniel Schaefer --- src/buffer.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/buffer.rs b/src/buffer.rs index d240535..cac7194 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -32,7 +32,11 @@ impl DrawTarget for Buffer { // Check if the pixel coordinates are out of bounds (negative or greater than // (63,63)). `DrawTarget` implementation are required to discard any out of bounds // pixels without returning an error or causing a panic. - if coord.x < self.width as i32 && coord.y < self.height as i32 { + if coord.x >= 0 + && coord.y >= 0 + && coord.x < self.width as i32 + && coord.y < self.height as i32 + { // Calculate the index in the framebuffer. let pixel = self.pixel(coord.x as usize, coord.y as usize).unwrap(); pixel.red = color.r();