From 0a1524f4f6f791fde05e681fbabd0787636ebced Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 2 Mar 2023 16:46:56 +0100 Subject: src/anim: fix off-by-one oob write for bitmaps --- src/anim-atlas.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp index 434f34b6..8ddd73d6 100644 --- a/src/anim-atlas.cpp +++ b/src/anim-atlas.cpp @@ -158,11 +158,13 @@ void anim_atlas::make_bitmask_(const ImageView2D& tex, BitArray& array) (unsigned char)(buf[7*4] >= amin) << 7); dest[dst_idx] = value; } - dest[(height-j-1)*width+i >> 3] = 0; - for (; i < width; i++) + if (i < width) { - unsigned char alpha = data[(j*stride + i*4)+3]; - array.set((height-j-1)*width + i, alpha >= amin); + dest[(height-j-1)*width+i >> 3] = 0; + do { + unsigned char alpha = data[(j*stride + i*4)+3]; + array.set((height-j-1)*width + i, alpha >= amin); + } while (++i < width); } } } -- cgit v1.2.3