rtextures: Fix ImageFromImage crash (#2594)

Height of the rectangle can be float, which
may lead to doing extra iteration of loop and
writing out of bounds.
This commit is contained in:
Piotr Wierciński
2022-07-26 20:53:36 +02:00
committed by GitHub
parent 6f3a633f2e
commit 5a2f25cc7c

View File

@@ -879,7 +879,7 @@ Image ImageFromImage(Image image, Rectangle rec)
result.format = image.format; result.format = image.format;
result.mipmaps = 1; result.mipmaps = 1;
for (int y = 0; y < rec.height; y++) for (int y = 0; y < (int)rec.height; y++)
{ {
memcpy(((unsigned char *)result.data) + y*(int)rec.width*bytesPerPixel, ((unsigned char *)image.data) + ((y + (int)rec.y)*image.width + (int)rec.x)*bytesPerPixel, (int)rec.width*bytesPerPixel); memcpy(((unsigned char *)result.data) + y*(int)rec.width*bytesPerPixel, ((unsigned char *)image.data) + ((y + (int)rec.y)*image.width + (int)rec.x)*bytesPerPixel, (int)rec.width*bytesPerPixel);
} }