From 983f178b7d3ebf002ef3ec3cdf73f93766bfccd0 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 24 Nov 2023 19:31:30 -0500 Subject: [PATCH] render: Clip lines before Bresenham algorithm generates points. Otherwise, a massive line might generate gigabytes worth of points to render, which the backend would simply throw away anyhow. Fixes #8113. (cherry picked from commit 4339647d900bb8559ac3f6258166d21fe6d72a9a) --- src/render/SDL_render.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 533a2fe524..e7006fb407 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -2755,6 +2755,18 @@ static int RenderLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x2, i int retval; SDL_bool isstack; SDL_FPoint *points; + SDL_Rect clip_rect; + + /* the backend might clip this further to the clipping rect, but we + just want a basic safety against generating millions of points for + massive lines. */ + clip_rect.x = (int) renderer->viewport.x; + clip_rect.y = (int) renderer->viewport.y; + clip_rect.w = (int) renderer->viewport.w; + clip_rect.h = (int) renderer->viewport.h; + if (!SDL_IntersectRectAndLine(&clip_rect, &x1, &y1, &x2, &y2)) { + return 0; + } deltax = SDL_abs(x2 - x1); deltay = SDL_abs(y2 - y1);