From 50a0df805fa45698cb1d82444be82f2703773b42 Mon Sep 17 00:00:00 2001 From: Jinny You Date: Thu, 9 Jan 2025 16:30:49 +0800 Subject: [PATCH] sw_engine: Fix buffer overflow in texture mapping rasterizer Fix heap buffer overflow in texture mapping rasterizer by adding proper bounds checking for texture coordinates. This prevents accessing memory outside of the allocated image buffer during texture sampling and interpolation. --- src/renderer/sw_engine/tvgSwRasterTexmap.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/sw_engine/tvgSwRasterTexmap.h b/src/renderer/sw_engine/tvgSwRasterTexmap.h index ed271ed7..b17f3c27 100644 --- a/src/renderer/sw_engine/tvgSwRasterTexmap.h +++ b/src/renderer/sw_engine/tvgSwRasterTexmap.h @@ -336,9 +336,9 @@ static void _rasterPolygonImageSegment(SwSurface* surface, const SwImage* image, //Draw horizontal line while (x++ < x2) { uu = (int) u; - if (uu >= sw) continue; + if (uu < 0 || uu >= sw) continue; vv = (int) v; - if (vv >= sh) continue; + if (vv < 0 || vv >= sh) continue; ar = (int)(255.0f * (1.0f - modff(u, &iptr))); ab = (int)(255.0f * (1.0f - modff(v, &iptr)));