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 <nunes.erico@gmail.com>
Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12055>
(cherry picked from commit e6cdb01c51)
This commit is contained in:
Erico Nunes 2021-07-25 13:48:59 +02:00 committed by Dylan Baker
parent 0eb551f658
commit fc9650d1f3
2 changed files with 3 additions and 3 deletions

View file

@ -112,7 +112,7 @@
"description": "lima: avoid crash with negative viewport values",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null
},

View file

@ -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;