diff --git a/ext/gd/libgd/gd_interpolation.c b/ext/gd/libgd/gd_interpolation.c index 5d9e991127c49..0ca79a7ad5344 100644 --- a/ext/gd/libgd/gd_interpolation.c +++ b/ext/gd/libgd/gd_interpolation.c @@ -2461,10 +2461,18 @@ int gdTransformAffineBoundingBox(gdRectPtr src, const double affine[6], gdRectPt if (max.y < extent[i].y) max.y=extent[i].y; } + double twidth = floor(max.x - min.x) - 1; + double theight = floor(max.y - min.y); + + if (twidth < (double)INT_MIN || twidth > (double)INT_MAX) + twidth = 0.0; + if (theight < (double)INT_MIN || theight > (double)INT_MAX) + theight = 0.0; + bbox->x = (int) min.x; bbox->y = (int) min.y; - bbox->width = (int) floor(max.x - min.x) - 1; - bbox->height = (int) floor(max.y - min.y); + bbox->width = (int) twidth; + bbox->height = (int) theight; return GD_TRUE; }