File ImageMagick-CVE-2022-32546.patch of Package ImageMagick.30356
Index: ImageMagick-7.0.7-34/coders/pcl.c
===================================================================
--- ImageMagick-7.0.7-34.orig/coders/pcl.c
+++ ImageMagick-7.0.7-34/coders/pcl.c
@@ -143,6 +143,18 @@ static MagickBooleanType IsPCL(const uns
% o exception: return any errors or warnings in this structure.
%
*/
+static inline ssize_t CastDoubleToLong(const double value)
+{
+ if (IsNaN(value) != 0)
+ return(0);
+ if (floor(value) > ((double) SSIZE_MAX-1))
+ return((ssize_t) SSIZE_MAX);
+ if (ceil(value) < ((double) (-(SSIZE_MAX)-1)))
+ return((ssize_t) (-(SSIZE_MAX)-1));
+ return((ssize_t) value);
+}
+
+
static Image *ReadPCLImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
#define CropBox "CropBox"
@@ -294,8 +306,8 @@ static Image *ReadPCLImage(const ImageIn
/*
Set PCL render geometry.
*/
- width=(size_t) floor(bounds.x2-bounds.x1+0.5);
- height=(size_t) floor(bounds.y2-bounds.y1+0.5);
+ width=(size_t)CastDoubleToLong(floor(bounds.x2-bounds.x1+0.5));
+ height=(size_t)CastDoubleToLong(floor(bounds.y2-bounds.y1+0.5));
if (width > page.width)
page.width=width;
if (height > page.height)