From dd9434bc360af96642325ce91a98d20a0c1cd2b4 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sat, 31 Dec 2022 05:50:35 +0200 Subject: [PATCH] lua_bitmap_composite: Don't OOB with outside if no right gap If lua_bitmap_composite encountered a cut, it warped to the right edge of the gap and then proceeded to composite a pixel. This is incorrect, because the right edge can be beyond draw area, resulting OOB access. Fix this by checking that the warped right edge is in draw area, and if not, moving to next row. --- include/lua/bitmap.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/lua/bitmap.hpp b/include/lua/bitmap.hpp index 70efcd51..4114bbc9 100644 --- a/include/lua/bitmap.hpp +++ b/include/lua/bitmap.hpp @@ -164,12 +164,14 @@ template void lua_bitmap_composite(struct framebuffer::fb& s bool cut = outside && sY.in(r); if(cut && sX.in(xmin)) { xmin = sX.high(); - eptr += (sX.high() - X.low()); + eptr += (sX.high() - X.low()); } for(uint32_t c = xmin; c < X.high(); c++, eptr++) { if(__builtin_expect(cut && c == sX.low(), 0)) { c += sX.size(); eptr += sX.size(); + //Don't write outside the framebuffer space if there is no right gap. + if(c >= X.high()) break; } bmp.draw(r * stride + c, rptr[eptr]); } -- 2.11.4.GIT