From e6cdb01c517b42dece9ed532fd6eba7a74aa8f71 Mon Sep 17 00:00:00 2001 From: Erico Nunes Date: Sun, 25 Jul 2021 13:48:59 +0200 Subject: [PATCH] lima: avoid crash with negative viewport values The viewport value computations done in lima_set_viewport_states can result in a negative value for viewport. These could end up converted to unsigned values in lima_clip_scissor_to_viewport causing crashes from invalid scissor commands. Prevent this by limiting the minimum value to zero as is already done for the left and bottom values. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2938 Cc: mesa-stable Signed-off-by: Erico Nunes Reviewed-by: Vasily Khoruzhick Part-of: --- src/gallium/drivers/lima/lima_draw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/lima/lima_draw.c b/src/gallium/drivers/lima/lima_draw.c index 3d29fcc..161fc72 100644 --- a/src/gallium/drivers/lima/lima_draw.c +++ b/src/gallium/drivers/lima/lima_draw.c @@ -72,14 +72,14 @@ lima_clip_scissor_to_viewport(struct lima_context *ctx) viewport_left = MAX2(ctx->viewport.left, 0); cscissor->minx = MAX2(cscissor->minx, viewport_left); - viewport_right = MIN2(ctx->viewport.right, fb->base.width); + viewport_right = MIN2(MAX2(ctx->viewport.right, 0), fb->base.width); cscissor->maxx = MIN2(cscissor->maxx, viewport_right); if (cscissor->minx > cscissor->maxx) cscissor->minx = cscissor->maxx; viewport_bottom = MAX2(ctx->viewport.bottom, 0); cscissor->miny = MAX2(cscissor->miny, viewport_bottom); - viewport_top = MIN2(ctx->viewport.top, fb->base.height); + viewport_top = MIN2(MAX2(ctx->viewport.top, 0), fb->base.height); cscissor->maxy = MIN2(cscissor->maxy, viewport_top); if (cscissor->miny > cscissor->maxy) cscissor->miny = cscissor->maxy; -- 2.7.4