From 19689b441412903c2ac097185661a30b2ca3fd51 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Tue, 14 Jan 2025 12:16:02 +0000 Subject: [PATCH] PicoGraphics: Fix overflow bug in p4 pixel span. A properly aligned zero length pixel span would cause a single pixel to be drawn, the length overflowed and a subsequent 2GB of pixels drawn by the main loop. Add a simple check to discard any attempt to draw zero length spans. Fixes pimoroni/pimoroni-pico-rp2350#32 --- libraries/pico_graphics/pico_graphics_pen_p4.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/pico_graphics/pico_graphics_pen_p4.cpp b/libraries/pico_graphics/pico_graphics_pen_p4.cpp index 68b3d62c..dfba55af 100644 --- a/libraries/pico_graphics/pico_graphics_pen_p4.cpp +++ b/libraries/pico_graphics/pico_graphics_pen_p4.cpp @@ -70,6 +70,10 @@ namespace pimoroni { } void PicoGraphics_PenP4::set_pixel_span(const Point &p, uint l) { + // prevent a zero length span causing an overflow in 'l' + // and trying to write 2GB of pixels. + if (l == 0) {return;} + auto i = (p.x + p.y * bounds.w); // pointer to byte in framebuffer that contains this pixel