From b67d4ef2ddf142d6bee0ea5d0bc70a305a4c1121 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Mon, 9 Mar 2026 17:47:59 +0100 Subject: [PATCH] Fix "fl_draw_image() with horizontal flip reads out of bounds" (#1369) --- src/Fl_Graphics_Driver.cxx | 2 +- src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Fl_Graphics_Driver.cxx b/src/Fl_Graphics_Driver.cxx index e127e4190..7fb892b95 100644 --- a/src/Fl_Graphics_Driver.cxx +++ b/src/Fl_Graphics_Driver.cxx @@ -480,7 +480,7 @@ void Fl_Graphics_Driver::draw_image_general_(const uchar *buf, int X, int Y, int data.buf = buf; data.D_in = d_corrected; data.D_out = d_out; - data.L = (L ? L : W * d_corrected); + data.L = (L ? L : W * abs(d_corrected)); if (alpha) d_out |= FL_IMAGE_WITH_ALPHA; fl_graphics_driver->draw_image((Fl_Draw_Image_Cb)scan_cb, &data, X, Y, W, H, d_out); } else diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx index 3fd13e5d1..3df45f888 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx @@ -105,7 +105,8 @@ static void innards(const uchar *buf, int X, int Y, int W, int H, } void Fl_Quartz_Graphics_Driver::draw_image(const uchar* buf, int x, int y, int w, int h, int d, int l){ - d &= ~FL_IMAGE_WITH_ALPHA; + if (d > 0) d &= ~FL_IMAGE_WITH_ALPHA; + else if (!(d & FL_IMAGE_WITH_ALPHA)) d |= FL_IMAGE_WITH_ALPHA; innards(buf,x,y,w,h,d,l,(d<3&&d>-3),0,0,gc_,this); } void Fl_Quartz_Graphics_Driver::draw_image(Fl_Draw_Image_Cb cb, void* data,