From 52def8dc270ca9be9a8fc581edbbecc4ca6f6931 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Thu, 3 Oct 2024 12:30:34 +0200 Subject: [PATCH] sw_engine: ++exception handling Prevent the infinite loop in the worst case @Issue: https://github.com/thorvg/thorvg/issues/2651 --- src/renderer/sw_engine/tvgSwRle.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/renderer/sw_engine/tvgSwRle.cpp b/src/renderer/sw_engine/tvgSwRle.cpp index 417c7d2d..84c497fb 100644 --- a/src/renderer/sw_engine/tvgSwRle.cpp +++ b/src/renderer/sw_engine/tvgSwRle.cpp @@ -558,7 +558,12 @@ static void _lineTo(RleWorker& rw, const SwPoint& to) /* The fundamental value `prod' determines which side and the */ /* exact coordinate where the line exits current cell. It is */ /* also easily updated when moving from one cell to the next. */ + size_t idx = 0; do { + if (++idx > 1000000000) { + TVGERR("SW_ENGINE", "Iteration limit reached during RLE generation. The resulting render may be incorrect."); + break; + } auto px = diff.x * ONE_PIXEL; auto py = diff.y * ONE_PIXEL;