Validate that image rect drawing is inside the image so we don't overflow a buffer
This commit is contained in:
parent
b9a10b5db7
commit
145ae839f1
|
|
@ -3134,6 +3134,20 @@ void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color)
|
||||||
if (rec.width < 0) rec.width = 0;
|
if (rec.width < 0) rec.width = 0;
|
||||||
if (rec.height < 0) rec.height = 0;
|
if (rec.height < 0) rec.height = 0;
|
||||||
|
|
||||||
|
// clamp the size the the image bounds
|
||||||
|
if (rec.x + rec.width >= dst->width)
|
||||||
|
rec.width = dst->width - rec.x;
|
||||||
|
|
||||||
|
if (rec.y + rec.height >= dst->height)
|
||||||
|
rec.height = dst->height - rec.y;
|
||||||
|
|
||||||
|
// check if the rect is even inside the image
|
||||||
|
if (rec.x > dst->width || rec.y > dst->height)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (rec.x + rec.width < 0 || rec.y + rec.height < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
int sy = (int)rec.y;
|
int sy = (int)rec.y;
|
||||||
int sx = (int)rec.x;
|
int sx = (int)rec.x;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user