summaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-support/imagemagick/files/0011-ImageMagick-Add-support-patch-2-to-fix-CVE-2023-3415.patch
diff options
context:
space:
mode:
authorDivyanshu Rathore <Divyanshu.Rathore@bmwtechworks.in>2025-12-12 20:29:47 +0530
committerGyorgy Sarvari <skandigraun@gmail.com>2025-12-12 22:06:56 +0100
commit2114ae5f26a71e38bc653b5376ea3c426eb5e157 (patch)
tree1d30e70955970a64196ac33ea044bcb9719b8019 /meta-oe/recipes-support/imagemagick/files/0011-ImageMagick-Add-support-patch-2-to-fix-CVE-2023-3415.patch
parent3a86962b263bb5ba4a7719854bfde87404e83f34 (diff)
downloadmeta-openembedded-2114ae5f26a71e38bc653b5376ea3c426eb5e157.tar.gz
ImageMagick: Fix CVE-2023-34151
Backport the fix for CVE-2023-34151 Upstream-Status: Backport [https://github.com/ImageMagick/ImageMagick/commit/3d6d98d8a2be30d74172ab43b5b8e874d2deb158] Add below patch to fix 0011-ImageMagick-Fix-CVE-2023-34151.patch Add below support patch to fix 0011-ImageMagick-Add-support-patch-1-to-fix-CVE-2023-3415.patch 0011-ImageMagick-Add-support-patch-2-to-fix-CVE-2023-3415.patch 0011-ImageMagick-Add-support-patch-3-to-fix-CVE-2023-3415.patch Signed-off-by: Divyanshu Rathore <Divyanshu.Rathore@bmwtechworks.in> Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
Diffstat (limited to 'meta-oe/recipes-support/imagemagick/files/0011-ImageMagick-Add-support-patch-2-to-fix-CVE-2023-3415.patch')
-rw-r--r--meta-oe/recipes-support/imagemagick/files/0011-ImageMagick-Add-support-patch-2-to-fix-CVE-2023-3415.patch973
1 files changed, 973 insertions, 0 deletions
diff --git a/meta-oe/recipes-support/imagemagick/files/0011-ImageMagick-Add-support-patch-2-to-fix-CVE-2023-3415.patch b/meta-oe/recipes-support/imagemagick/files/0011-ImageMagick-Add-support-patch-2-to-fix-CVE-2023-3415.patch
new file mode 100644
index 0000000000..7d73ba08c1
--- /dev/null
+++ b/meta-oe/recipes-support/imagemagick/files/0011-ImageMagick-Add-support-patch-2-to-fix-CVE-2023-3415.patch
@@ -0,0 +1,973 @@
1From 95a74f9639872c667213b9ce201c1a388d538d30 Mon Sep 17 00:00:00 2001
2From: Divyanshu Rathore <Divyanshu.Rathore@bmwtechworks.in>
3Date: Tue, 2 Dec 2025 14:02:56 +0530
4Subject: [PATCH 16/18] ImageMagick: Add support patch 2 to fix CVE-2023-34151
5
6Upstream-Status: Backport [https://github.com/ImageMagick/ImageMagick/commit/f7b5682435d37ad5ea8142d69629c93228e6376d]
7
8Comment: Refreshed hunk to match latest kirkstone
9
10Signed-off-by: Divyanshu Rathore <Divyanshu.Rathore@bmwtechworks.in>
11---
12 MagickCore/annotate.c | 8 ++---
13 MagickCore/draw.c | 60 ++++++++++++++++++-------------------
14 MagickCore/effect.c | 8 ++---
15 MagickCore/gem.c | 2 +-
16 MagickCore/geometry.c | 24 +++++++--------
17 MagickCore/image-private.h | 37 ++++++++++++++++-------
18 MagickCore/image.c | 20 ++++++-------
19 MagickCore/pixel.c | 36 +++++++++++-----------
20 MagickCore/property.c | 4 +--
21 MagickCore/shear.c | 22 +++++++-------
22 MagickCore/studio.h | 2 --
23 MagickCore/transform.c | 4 +--
24 MagickCore/visual-effects.c | 40 ++++++++++++-------------
25 MagickWand/drawing-wand.c | 8 ++---
26 MagickWand/studio.h | 2 --
27 coders/histogram.c | 6 ++--
28 coders/jpeg.c | 3 +-
29 coders/png.c | 12 ++++----
30 coders/tiff.c | 4 +--
31 coders/txt.c | 4 +--
32 20 files changed, 159 insertions(+), 147 deletions(-)
33
34diff --git a/MagickCore/annotate.c b/MagickCore/annotate.c
35index 4be938be5..14f8d05d8 100644
36--- a/MagickCore/annotate.c
37+++ b/MagickCore/annotate.c
38@@ -1734,8 +1734,8 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
39
40 if (status == MagickFalse)
41 continue;
42- x_offset=CastDoubleToLong(ceil(point.x-0.5));
43- y_offset=CastDoubleToLong(ceil(point.y+y-0.5));
44+ x_offset=CastDoubleToSSizeT(ceil(point.x-0.5));
45+ y_offset=CastDoubleToSSizeT(ceil(point.y+y-0.5));
46 if ((y_offset < 0) || (y_offset >= (ssize_t) image->rows))
47 continue;
48 q=(Quantum *) NULL;
49@@ -1750,7 +1750,7 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
50 n=y*bitmap->bitmap.pitch;
51 for (x=0; x < (ssize_t) bitmap->bitmap.width; x++, n++)
52 {
53- x_offset=CastDoubleToLong(ceil(point.x+x-0.5));
54+ x_offset=CastDoubleToSSizeT(ceil(point.x+x-0.5));
55 if ((x_offset < 0) || (x_offset >= (ssize_t) image->columns))
56 {
57 if (q != (Quantum *) NULL)
58@@ -2102,7 +2102,7 @@ static MagickBooleanType RenderPostscript(Image *image,
59 crop_info=GetImageBoundingBox(annotate_image,exception);
60 crop_info.height=(size_t) ((resolution.y/DefaultResolution)*
61 ExpandAffine(&draw_info->affine)*draw_info->pointsize+0.5);
62- crop_info.y=CastDoubleToLong(ceil((resolution.y/DefaultResolution)*
63+ crop_info.y=CastDoubleToSSizeT(ceil((resolution.y/DefaultResolution)*
64 extent.y/8.0-0.5));
65 (void) FormatLocaleString(geometry,MagickPathExtent,
66 "%.20gx%.20g%+.20g%+.20g",(double) crop_info.width,(double)
67diff --git a/MagickCore/draw.c b/MagickCore/draw.c
68index facea115e..02df7d231 100644
69--- a/MagickCore/draw.c
70+++ b/MagickCore/draw.c
71@@ -1233,8 +1233,8 @@ MagickExport MagickBooleanType DrawAffineImage(Image *image,
72 edge.y2=MagickMin(max.y,(double) image->rows-1.0);
73 inverse_affine=InverseAffineMatrix(affine);
74 GetPixelInfo(image,&zero);
75- start=CastDoubleToLong(ceil(edge.y1-0.5));
76- stop=CastDoubleToLong(floor(edge.y2+0.5));
77+ start=CastDoubleToSSizeT(ceil(edge.y1-0.5));
78+ stop=CastDoubleToSSizeT(floor(edge.y2+0.5));
79 source_view=AcquireVirtualCacheView(source,exception);
80 image_view=AcquireAuthenticCacheView(image,exception);
81 #if defined(MAGICKCORE_OPENMP_SUPPORT)
82@@ -1267,16 +1267,16 @@ MagickExport MagickBooleanType DrawAffineImage(Image *image,
83 inverse_edge=AffineEdge(source,&inverse_affine,(double) y,&edge);
84 if (inverse_edge.x2 < inverse_edge.x1)
85 continue;
86- q=GetCacheViewAuthenticPixels(image_view,CastDoubleToLong(
87- ceil(inverse_edge.x1-0.5)),y,(size_t) CastDoubleToLong(floor(
88+ q=GetCacheViewAuthenticPixels(image_view,CastDoubleToSSizeT(
89+ ceil(inverse_edge.x1-0.5)),y,(size_t) CastDoubleToSSizeT(floor(
90 inverse_edge.x2+0.5)-ceil(inverse_edge.x1-0.5)+1),1,exception);
91 if (q == (Quantum *) NULL)
92 continue;
93 pixel=zero;
94 composite=zero;
95 x_offset=0;
96- for (x=CastDoubleToLong(ceil(inverse_edge.x1-0.5));
97- x <= CastDoubleToLong(floor(inverse_edge.x2+0.5)); x++)
98+ for (x=CastDoubleToSSizeT(ceil(inverse_edge.x1-0.5));
99+ x <= CastDoubleToSSizeT(floor(inverse_edge.x2+0.5)); x++)
100 {
101 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
102 inverse_affine.tx;
103@@ -2090,8 +2090,8 @@ MagickExport MagickBooleanType DrawGradientImage(Image *image,
104 case UndefinedSpread:
105 case PadSpread:
106 {
107- if ((x != CastDoubleToLong(ceil(gradient_vector->x1-0.5))) ||
108- (y != CastDoubleToLong(ceil(gradient_vector->y1-0.5))))
109+ if ((x != CastDoubleToSSizeT(ceil(gradient_vector->x1-0.5))) ||
110+ (y != CastDoubleToSSizeT(ceil(gradient_vector->y1-0.5))))
111 {
112 offset=GetStopColorOffset(gradient,x,y);
113 if (gradient->type != RadialGradient)
114@@ -2118,8 +2118,8 @@ MagickExport MagickBooleanType DrawGradientImage(Image *image,
115 }
116 case ReflectSpread:
117 {
118- if ((x != CastDoubleToLong(ceil(gradient_vector->x1-0.5))) ||
119- (y != CastDoubleToLong(ceil(gradient_vector->y1-0.5))))
120+ if ((x != CastDoubleToSSizeT(ceil(gradient_vector->x1-0.5))) ||
121+ (y != CastDoubleToSSizeT(ceil(gradient_vector->y1-0.5))))
122 {
123 offset=GetStopColorOffset(gradient,x,y);
124 if (gradient->type != RadialGradient)
125@@ -2160,8 +2160,8 @@ MagickExport MagickBooleanType DrawGradientImage(Image *image,
126
127 antialias=MagickFalse;
128 repeat=0.0;
129- if ((x != CastDoubleToLong(ceil(gradient_vector->x1-0.5))) ||
130- (y != CastDoubleToLong(ceil(gradient_vector->y1-0.5))))
131+ if ((x != CastDoubleToSSizeT(ceil(gradient_vector->x1-0.5))) ||
132+ (y != CastDoubleToSSizeT(ceil(gradient_vector->y1-0.5))))
133 {
134 offset=GetStopColorOffset(gradient,x,y);
135 if (gradient->type == LinearGradient)
136@@ -3457,21 +3457,21 @@ static MagickBooleanType RenderMVGContent(Image *image,
137 (void) GetNextToken(q,&q,extent,token);
138 (void) CopyMagickString(name,token,MagickPathExtent);
139 (void) GetNextToken(q,&q,extent,token);
140- bounds.x=CastDoubleToLong(ceil(GetDrawValue(token,
141+ bounds.x=CastDoubleToSSizeT(ceil(GetDrawValue(token,
142 &next_token)-0.5));
143 if (token == next_token)
144 ThrowPointExpectedException(token,exception);
145 (void) GetNextToken(q,&q,extent,token);
146 if (*token == ',')
147 (void) GetNextToken(q,&q,extent,token);
148- bounds.y=CastDoubleToLong(ceil(GetDrawValue(token,
149+ bounds.y=CastDoubleToSSizeT(ceil(GetDrawValue(token,
150 &next_token)-0.5));
151 if (token == next_token)
152 ThrowPointExpectedException(token,exception);
153 (void) GetNextToken(q,&q,extent,token);
154 if (*token == ',')
155 (void) GetNextToken(q,&q,extent,token);
156- bounds.width=(size_t) CastDoubleToLong(floor(GetDrawValue(
157+ bounds.width=(size_t) CastDoubleToSSizeT(floor(GetDrawValue(
158 token,&next_token)+0.5));
159 if (token == next_token)
160 ThrowPointExpectedException(token,exception);
161@@ -3882,28 +3882,28 @@ static MagickBooleanType RenderMVGContent(Image *image,
162 if (LocaleCompare("viewbox",keyword) == 0)
163 {
164 (void) GetNextToken(q,&q,extent,token);
165- graphic_context[n]->viewbox.x=CastDoubleToLong(ceil(
166+ graphic_context[n]->viewbox.x=CastDoubleToSSizeT(ceil(
167 GetDrawValue(token,&next_token)-0.5));
168 if (token == next_token)
169 ThrowPointExpectedException(token,exception);
170 (void) GetNextToken(q,&q,extent,token);
171 if (*token == ',')
172 (void) GetNextToken(q,&q,extent,token);
173- graphic_context[n]->viewbox.y=CastDoubleToLong(ceil(
174+ graphic_context[n]->viewbox.y=CastDoubleToSSizeT(ceil(
175 GetDrawValue(token,&next_token)-0.5));
176 if (token == next_token)
177 ThrowPointExpectedException(token,exception);
178 (void) GetNextToken(q,&q,extent,token);
179 if (*token == ',')
180 (void) GetNextToken(q,&q,extent,token);
181- graphic_context[n]->viewbox.width=(size_t) CastDoubleToLong(
182+ graphic_context[n]->viewbox.width=(size_t) CastDoubleToSSizeT(
183 floor(GetDrawValue(token,&next_token)+0.5));
184 if (token == next_token)
185 ThrowPointExpectedException(token,exception);
186 (void) GetNextToken(q,&q,extent,token);
187 if (*token == ',')
188 (void) GetNextToken(q,&q,extent,token);
189- graphic_context[n]->viewbox.height=(size_t) CastDoubleToLong(
190+ graphic_context[n]->viewbox.height=(size_t) CastDoubleToSSizeT(
191 floor(GetDrawValue(token,&next_token)+0.5));
192 if (token == next_token)
193 ThrowPointExpectedException(token,exception);
194@@ -5017,8 +5017,8 @@ static MagickBooleanType DrawPolygonPrimitive(Image *image,
195 GetPixelInfo(image,&pixel);
196 for ( ; x <= stop_x; x++)
197 {
198- if ((x == CastDoubleToLong(ceil(primitive_info->point.x-0.5))) &&
199- (y == CastDoubleToLong(ceil(primitive_info->point.y-0.5))))
200+ if ((x == CastDoubleToSSizeT(ceil(primitive_info->point.x-0.5))) &&
201+ (y == CastDoubleToSSizeT(ceil(primitive_info->point.y-0.5))))
202 {
203 GetFillColor(draw_info,x-start_x,y-start_y,&pixel,exception);
204 SetPixelViaPixelInfo(image,&pixel,q);
205@@ -5164,8 +5164,8 @@ static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info)
206 coordinates,
207 y;
208
209- x=CastDoubleToLong(ceil(primitive_info->point.x-0.5));
210- y=CastDoubleToLong(ceil(primitive_info->point.y-0.5));
211+ x=CastDoubleToSSizeT(ceil(primitive_info->point.x-0.5));
212+ y=CastDoubleToSSizeT(ceil(primitive_info->point.y-0.5));
213 switch (primitive_info->primitive)
214 {
215 case AlphaPrimitive:
216@@ -5278,8 +5278,8 @@ MagickExport MagickBooleanType DrawPrimitive(Image *image,
217 status&=SetImageMask(image,CompositePixelMask,draw_info->composite_mask,
218 exception);
219 }
220- x=CastDoubleToLong(ceil(primitive_info->point.x-0.5));
221- y=CastDoubleToLong(ceil(primitive_info->point.y-0.5));
222+ x=CastDoubleToSSizeT(ceil(primitive_info->point.x-0.5));
223+ y=CastDoubleToSSizeT(ceil(primitive_info->point.y-0.5));
224 image_view=AcquireAuthenticCacheView(image,exception);
225 switch (primitive_info->primitive)
226 {
227@@ -5557,8 +5557,8 @@ MagickExport MagickBooleanType DrawPrimitive(Image *image,
228 composite_images=DestroyImageList(composite_images);
229 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
230 NULL,(void *) NULL);
231- x1=CastDoubleToLong(ceil(primitive_info[1].point.x-0.5));
232- y1=CastDoubleToLong(ceil(primitive_info[1].point.y-0.5));
233+ x1=CastDoubleToSSizeT(ceil(primitive_info[1].point.x-0.5));
234+ y1=CastDoubleToSSizeT(ceil(primitive_info[1].point.y-0.5));
235 if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) ||
236 ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows)))
237 {
238@@ -6167,7 +6167,7 @@ static MagickBooleanType TraceArcPath(MVGInfo *mvg_info,const PointInfo start,
239 else
240 if ((theta > 0.0) && (sweep == MagickFalse))
241 theta-=2.0*MagickPI;
242- arc_segments=(size_t) CastDoubleToLong(ceil(fabs((double) (theta/(0.5*
243+ arc_segments=(size_t) CastDoubleToSSizeT(ceil(fabs((double) (theta/(0.5*
244 MagickPI+MagickEpsilon)))));
245 status=MagickTrue;
246 p=primitive_info;
247@@ -7517,7 +7517,7 @@ static PrimitiveInfo *TraceStrokePolygon(const DrawInfo *draw_info,
248 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
249 if (theta.q < theta.p)
250 theta.q+=2.0*MagickPI;
251- arc_segments=(size_t) CastDoubleToLong(ceil((double) ((theta.
252+ arc_segments=(size_t) CastDoubleToSSizeT(ceil((double) ((theta.
253 q-theta.p)/(2.0*sqrt(PerceptibleReciprocal(mid))))));
254 CheckPathExtent(MaxStrokePad,arc_segments+MaxStrokePad);
255 stroke_q[q].x=box_q[1].x;
256@@ -7590,7 +7590,7 @@ static PrimitiveInfo *TraceStrokePolygon(const DrawInfo *draw_info,
257 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
258 if (theta.p < theta.q)
259 theta.p+=2.0*MagickPI;
260- arc_segments=(size_t) CastDoubleToLong(ceil((double) ((theta.p-
261+ arc_segments=(size_t) CastDoubleToSSizeT(ceil((double) ((theta.p-
262 theta.q)/(2.0*sqrt((double) (1.0/mid))))));
263 CheckPathExtent(arc_segments+MaxStrokePad,MaxStrokePad);
264 stroke_p[p++]=box_p[1];
265diff --git a/MagickCore/effect.c b/MagickCore/effect.c
266index bfb1363f2..a37a1999e 100644
267--- a/MagickCore/effect.c
268+++ b/MagickCore/effect.c
269@@ -288,7 +288,7 @@ MagickExport Image *AdaptiveBlurImage(const Image *image,const double radius,
270 center,
271 j;
272
273- j=CastDoubleToLong(ceil((double) width*(1.0-QuantumScale*
274+ j=CastDoubleToSSizeT(ceil((double) width*(1.0-QuantumScale*
275 GetPixelIntensity(edge_image,r))-0.5));
276 if (j < 0)
277 j=0;
278@@ -609,7 +609,7 @@ MagickExport Image *AdaptiveSharpenImage(const Image *image,const double radius,
279 center,
280 j;
281
282- j=CastDoubleToLong(ceil((double) width*(1.0-QuantumScale*
283+ j=CastDoubleToSSizeT(ceil((double) width*(1.0-QuantumScale*
284 GetPixelIntensity(edge_image,r))-0.5));
285 if (j < 0)
286 j=0;
287@@ -2402,9 +2402,9 @@ MagickExport Image *MotionBlurImage(const Image *image,const double radius,
288 point.y=(double) width*cos(DegreesToRadians(angle));
289 for (i=0; i < (ssize_t) width; i++)
290 {
291- offset[i].x=CastDoubleToLong(ceil((double) (i*point.y)/
292+ offset[i].x=CastDoubleToSSizeT(ceil((double) (i*point.y)/
293 hypot(point.x,point.y)-0.5));
294- offset[i].y=CastDoubleToLong(ceil((double) (i*point.x)/
295+ offset[i].y=CastDoubleToSSizeT(ceil((double) (i*point.x)/
296 hypot(point.x,point.y)-0.5));
297 }
298 /*
299diff --git a/MagickCore/gem.c b/MagickCore/gem.c
300index 2c5911f67..4eb8c3fc5 100644
301--- a/MagickCore/gem.c
302+++ b/MagickCore/gem.c
303@@ -692,7 +692,7 @@ MagickPrivate void ConvertHWBToRGB(const double hue,const double whiteness,
304 *blue=QuantumRange*v;
305 return;
306 }
307- i=CastDoubleToLong(floor(6.0*hue));
308+ i=CastDoubleToSSizeT(floor(6.0*hue));
309 f=6.0*hue-i;
310 if ((i & 0x01) != 0)
311 f=1.0-f;
312diff --git a/MagickCore/geometry.c b/MagickCore/geometry.c
313index 5c6e2ad69..dd46a96fc 100644
314--- a/MagickCore/geometry.c
315+++ b/MagickCore/geometry.c
316@@ -241,7 +241,7 @@ MagickExport MagickStatusType GetGeometry(const char *geometry,ssize_t *x,
317 if (LocaleNCompare(p,"0x",2) == 0)
318 *width=(size_t) strtol(p,&p,10);
319 else
320- *width=((size_t) floor(StringToDouble(p,&p)+0.5)) & 0x7fffffff;
321+ *width=CastDoubleToSizeT(StringToDouble(p,&p));
322 }
323 if (p != q)
324 flags|=WidthValue;
325@@ -260,7 +260,7 @@ MagickExport MagickStatusType GetGeometry(const char *geometry,ssize_t *x,
326 */
327 q=p;
328 if (height != (size_t *) NULL)
329- *height=((size_t) floor(StringToDouble(p,&p)+0.5)) & 0x7fffffff;
330+ *height=CastDoubleToSizeT(StringToDouble(p,&p));
331 if (p != q)
332 flags|=HeightValue;
333 }
334@@ -279,7 +279,7 @@ MagickExport MagickStatusType GetGeometry(const char *geometry,ssize_t *x,
335 }
336 q=p;
337 if (x != (ssize_t *) NULL)
338- *x=((ssize_t) ceil(StringToDouble(p,&p)-0.5)) & 0x7fffffff;
339+ *x=CastDoubleToSSizeT(StringToDouble(p,&p));
340 if (p != q)
341 {
342 flags|=XValue;
343@@ -300,7 +300,7 @@ MagickExport MagickStatusType GetGeometry(const char *geometry,ssize_t *x,
344 }
345 q=p;
346 if (y != (ssize_t *) NULL)
347- *y=((ssize_t) ceil(StringToDouble(p,&p)-0.5)) & 0x7fffffff;
348+ *y=CastDoubleToSSizeT(StringToDouble(p,&p));
349 if (p != q)
350 {
351 flags|=YValue;
352@@ -1285,8 +1285,8 @@ MagickExport MagickStatusType ParseGravityGeometry(const Image *image,
353 scale.y=geometry_info.sigma;
354 if ((status & SigmaValue) == 0)
355 scale.y=scale.x;
356- region_info->width=(size_t) floor((scale.x*image->columns/100.0)+0.5);
357- region_info->height=(size_t) floor((scale.y*image->rows/100.0)+0.5);
358+ region_info->width=CastDoubleToSizeT(scale.x*image->columns/100.0);
359+ region_info->height=CastDoubleToSizeT(scale.y*image->rows/100.0);
360 }
361 if ((flags & AspectRatioValue) != 0)
362 {
363@@ -1308,13 +1308,13 @@ MagickExport MagickStatusType ParseGravityGeometry(const Image *image,
364 if (geometry_ratio >= image_ratio)
365 {
366 region_info->width=image->columns;
367- region_info->height=(size_t) floor((double) (image->rows*image_ratio/
368- geometry_ratio)+0.5);
369+ region_info->height=CastDoubleToSizeT((double) image->rows*image_ratio/
370+ geometry_ratio);
371 }
372 else
373 {
374- region_info->width=(size_t) floor((double) (image->columns*
375- geometry_ratio/image_ratio)+0.5);
376+ region_info->width=CastDoubleToSizeT((double) image->columns*
377+ geometry_ratio/image_ratio);
378 region_info->height=image->rows;
379 }
380 }
381@@ -1450,8 +1450,8 @@ MagickExport MagickStatusType ParseMetaGeometry(const char *geometry,ssize_t *x,
382 }
383 else
384 {
385- *width=(size_t) floor((double) (PerceptibleReciprocal(
386- image_ratio)*former_width*geometry_ratio)+0.5);
387+ *width=CastDoubleToSizeT(PerceptibleReciprocal(
388+ image_ratio)*former_width*geometry_ratio);
389 *height=former_height;
390 }
391 former_width=(*width);
392diff --git a/MagickCore/image-private.h b/MagickCore/image-private.h
393index 59b88fb6f..694c19d54 100644
394--- a/MagickCore/image-private.h
395+++ b/MagickCore/image-private.h
396@@ -41,6 +41,9 @@ extern "C" {
397 #define MagickSQ1_2 0.70710678118654752440084436210484903928483593768847
398 #define MagickSQ2 1.41421356237309504880168872420969807856967187537695
399 #define MagickSQ2PI 2.50662827463100024161235523934010416269302368164062
400+#define MAGICK_SIZE_MAX (SIZE_MAX)
401+#define MAGICK_SSIZE_MAX (SSIZE_MAX)
402+#define MAGICK_SSIZE_MIN (-(SSIZE_MAX)-1)
403 #define MatteColor "#bdbdbd" /* gray */
404 #define PSDensityGeometry "72.0x72.0"
405 #define PSPageGeometry "612x792"
406@@ -50,17 +53,6 @@ extern "C" {
407 #define UndefinedCompressionQuality 0UL
408 #define UndefinedTicksPerSecond 100L
409
410-static inline ssize_t CastDoubleToLong(const double value)
411-{
412- if (IsNaN(value) != 0)
413- return(0);
414- if (value > (double) MAGICK_SSIZE_MAX)
415- return((ssize_t) MAGICK_SSIZE_MAX);
416- if (value < (double) MAGICK_SSIZE_MIN)
417- return((ssize_t) MAGICK_SSIZE_MIN);
418- return((ssize_t) value);
419-}
420-
421 static inline QuantumAny CastDoubleToQuantumAny(const double x)
422 {
423 if (IsNaN(x) != 0)
424@@ -72,6 +64,29 @@ static inline QuantumAny CastDoubleToQuantumAny(const double x)
425 return((QuantumAny) (x+0.5));
426 }
427
428+static inline size_t CastDoubleToSizeT(const double x)
429+{
430+ if (IsNaN(x) != 0)
431+ return(0);
432+ if (x > ((double) MAGICK_SIZE_MAX+0.5))
433+ return((size_t) MAGICK_SIZE_MAX);
434+ return((size_t) floor(x+0.5));
435+}
436+
437+static inline ssize_t CastDoubleToSSizeT(const double x)
438+{
439+ if (IsNaN(x) != 0)
440+ return(0);
441+ if (x > ((double) MAGICK_SSIZE_MAX+0.5))
442+ return((ssize_t) MAGICK_SSIZE_MAX);
443+ if (x < ((double) MAGICK_SSIZE_MIN-0.5))
444+ return((ssize_t) MAGICK_SSIZE_MIN);
445+ if (x >= 0.0)
446+ return((ssize_t) floor(x+0.5));
447+ return((ssize_t) ceil(x-0.5));
448+}
449+
450+
451 static inline double DegreesToRadians(const double degrees)
452 {
453 return((double) (MagickPI*degrees/180.0));
454diff --git a/MagickCore/image.c b/MagickCore/image.c
455index 3e6fdd114..7b8caa0d2 100644
456--- a/MagickCore/image.c
457+++ b/MagickCore/image.c
458@@ -282,21 +282,21 @@ MagickExport Image *AcquireImage(const ImageInfo *image_info,
459 if ((flags & GreaterValue) != 0)
460 {
461 if ((double) image->delay > floor(geometry_info.rho+0.5))
462- image->delay=(size_t) CastDoubleToLong(floor(
463+ image->delay=(size_t) CastDoubleToSSizeT(floor(
464 geometry_info.rho+0.5));
465 }
466 else
467 if ((flags & LessValue) != 0)
468 {
469 if ((double) image->delay < floor(geometry_info.rho+0.5))
470- image->ticks_per_second=CastDoubleToLong(floor(
471+ image->ticks_per_second=CastDoubleToSSizeT(floor(
472 geometry_info.sigma+0.5));
473 }
474 else
475- image->delay=(size_t) CastDoubleToLong(floor(
476+ image->delay=(size_t) CastDoubleToSSizeT(floor(
477 geometry_info.rho+0.5));
478 if ((flags & SigmaValue) != 0)
479- image->ticks_per_second=CastDoubleToLong(floor(
480+ image->ticks_per_second=CastDoubleToSSizeT(floor(
481 geometry_info.sigma+0.5));
482 }
483 option=GetImageOption(image_info,"dispose");
484@@ -881,18 +881,18 @@ MagickExport Image *CloneImage(const Image *image,const size_t columns,
485 scale=1.0;
486 if (image->columns != 0)
487 scale=(double) columns/(double) image->columns;
488- clone_image->page.width=(size_t) CastDoubleToLong(floor(scale*
489+ clone_image->page.width=(size_t) CastDoubleToSSizeT(floor(scale*
490 image->page.width+0.5));
491- clone_image->page.x=CastDoubleToLong(ceil(scale*image->page.x-0.5));
492- clone_image->tile_offset.x=CastDoubleToLong(ceil(scale*
493+ clone_image->page.x=CastDoubleToSSizeT(ceil(scale*image->page.x-0.5));
494+ clone_image->tile_offset.x=CastDoubleToSSizeT(ceil(scale*
495 image->tile_offset.x-0.5));
496 scale=1.0;
497 if (image->rows != 0)
498 scale=(double) rows/(double) image->rows;
499- clone_image->page.height=(size_t) CastDoubleToLong(floor(scale*
500+ clone_image->page.height=(size_t) CastDoubleToSSizeT(floor(scale*
501 image->page.height+0.5));
502- clone_image->page.y=CastDoubleToLong(ceil(scale*image->page.y-0.5));
503- clone_image->tile_offset.y=CastDoubleToLong(ceil(scale*
504+ clone_image->page.y=CastDoubleToSSizeT(ceil(scale*image->page.y-0.5));
505+ clone_image->tile_offset.y=CastDoubleToSSizeT(ceil(scale*
506 image->tile_offset.y-0.5));
507 clone_image->cache=ClonePixelCache(image->cache);
508 if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
509diff --git a/MagickCore/pixel.c b/MagickCore/pixel.c
510index 5c1c5296f..c2aea7c1d 100644
511--- a/MagickCore/pixel.c
512+++ b/MagickCore/pixel.c
513@@ -4515,8 +4515,8 @@ MagickExport MagickBooleanType InterpolatePixelChannel(
514 status=MagickTrue;
515 *pixel=0.0;
516 traits=GetPixelChannelTraits(image,channel);
517- x_offset=CastDoubleToLong(floor(x));
518- y_offset=CastDoubleToLong(floor(y));
519+ x_offset=CastDoubleToSSizeT(floor(x));
520+ y_offset=CastDoubleToSSizeT(floor(y));
521 interpolate=method;
522 if (interpolate == UndefinedInterpolatePixel)
523 interpolate=image->interpolate;
524@@ -4533,8 +4533,8 @@ MagickExport MagickBooleanType InterpolatePixelChannel(
525 if (interpolate == Average9InterpolatePixel)
526 {
527 count=3;
528- x_offset=CastDoubleToLong(floor(x+0.5)-1.0);
529- y_offset=CastDoubleToLong(floor(y+0.5)-1.0);
530+ x_offset=CastDoubleToSSizeT(floor(x+0.5)-1.0);
531+ y_offset=CastDoubleToSSizeT(floor(y+0.5)-1.0);
532 }
533 else
534 if (interpolate == Average16InterpolatePixel)
535@@ -4717,8 +4717,8 @@ MagickExport MagickBooleanType InterpolatePixelChannel(
536 }
537 case NearestInterpolatePixel:
538 {
539- x_offset=CastDoubleToLong(floor(x+0.5));
540- y_offset=CastDoubleToLong(floor(y+0.5));
541+ x_offset=CastDoubleToSSizeT(floor(x+0.5));
542+ y_offset=CastDoubleToSSizeT(floor(y+0.5));
543 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
544 if (p == (const Quantum *) NULL)
545 {
546@@ -4935,8 +4935,8 @@ MagickExport MagickBooleanType InterpolatePixelChannels(
547 assert(source->signature == MagickCoreSignature);
548 assert(source_view != (CacheView *) NULL);
549 status=MagickTrue;
550- x_offset=CastDoubleToLong(floor(x));
551- y_offset=CastDoubleToLong(floor(y));
552+ x_offset=CastDoubleToSSizeT(floor(x));
553+ y_offset=CastDoubleToSSizeT(floor(y));
554 interpolate=method;
555 if (interpolate == UndefinedInterpolatePixel)
556 interpolate=source->interpolate;
557@@ -4953,8 +4953,8 @@ MagickExport MagickBooleanType InterpolatePixelChannels(
558 if (interpolate == Average9InterpolatePixel)
559 {
560 count=3;
561- x_offset=CastDoubleToLong(floor(x+0.5)-1.0);
562- y_offset=CastDoubleToLong(floor(y+0.5)-1.0);
563+ x_offset=CastDoubleToSSizeT(floor(x+0.5)-1.0);
564+ y_offset=CastDoubleToSSizeT(floor(y+0.5)-1.0);
565 }
566 else
567 if (interpolate == Average16InterpolatePixel)
568@@ -5218,8 +5218,8 @@ MagickExport MagickBooleanType InterpolatePixelChannels(
569 }
570 case NearestInterpolatePixel:
571 {
572- x_offset=CastDoubleToLong(floor(x+0.5));
573- y_offset=CastDoubleToLong(floor(y+0.5));
574+ x_offset=CastDoubleToSSizeT(floor(x+0.5));
575+ y_offset=CastDoubleToSSizeT(floor(y+0.5));
576 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
577 if (p == (const Quantum *) NULL)
578 {
579@@ -5502,8 +5502,8 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
580 assert(image->signature == MagickCoreSignature);
581 assert(image_view != (CacheView *) NULL);
582 status=MagickTrue;
583- x_offset=CastDoubleToLong(floor(x));
584- y_offset=CastDoubleToLong(floor(y));
585+ x_offset=CastDoubleToSSizeT(floor(x));
586+ y_offset=CastDoubleToSSizeT(floor(y));
587 interpolate=method;
588 if (interpolate == UndefinedInterpolatePixel)
589 interpolate=image->interpolate;
590@@ -5522,8 +5522,8 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
591 if (interpolate == Average9InterpolatePixel)
592 {
593 count=3;
594- x_offset=CastDoubleToLong(floor(x+0.5)-1.0);
595- y_offset=CastDoubleToLong(floor(y+0.5)-1.0);
596+ x_offset=CastDoubleToSSizeT(floor(x+0.5)-1.0);
597+ y_offset=CastDoubleToSSizeT(floor(y+0.5)-1.0);
598 }
599 else if (interpolate == Average16InterpolatePixel)
600 {
601@@ -5847,8 +5847,8 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
602 }
603 case NearestInterpolatePixel:
604 {
605- x_offset=CastDoubleToLong(floor(x+0.5));
606- y_offset=CastDoubleToLong(floor(y+0.5));
607+ x_offset=CastDoubleToSSizeT(floor(x+0.5));
608+ y_offset=CastDoubleToSSizeT(floor(y+0.5));
609 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
610 if (p == (const Quantum *) NULL)
611 {
612diff --git a/MagickCore/property.c b/MagickCore/property.c
613index 1b42adaee..b13fa7a17 100644
614--- a/MagickCore/property.c
615+++ b/MagickCore/property.c
616@@ -4372,13 +4372,13 @@ MagickExport MagickBooleanType SetImageProperty(Image *image,
617 if ((flags & LessValue) != 0)
618 {
619 if ((double) image->delay < floor(geometry_info.rho+0.5))
620- image->delay=CastDoubleToLong(
621+ image->delay=CastDoubleToSSizeT(
622 floor(geometry_info.sigma+0.5));
623 }
624 else
625 image->delay=(size_t) floor(geometry_info.rho+0.5);
626 if ((flags & SigmaValue) != 0)
627- image->ticks_per_second=CastDoubleToLong(floor(
628+ image->ticks_per_second=CastDoubleToSSizeT(floor(
629 geometry_info.sigma+0.5));
630 return(MagickTrue);
631 }
632diff --git a/MagickCore/shear.c b/MagickCore/shear.c
633index 05703ca34..62a98013e 100644
634--- a/MagickCore/shear.c
635+++ b/MagickCore/shear.c
636@@ -163,10 +163,10 @@ static MagickBooleanType CropToFitImage(Image **image,
637 if (max.y < extent[i].y)
638 max.y=extent[i].y;
639 }
640- geometry.x=CastDoubleToLong(ceil(min.x-0.5));
641- geometry.y=CastDoubleToLong(ceil(min.y-0.5));
642- geometry.width=(size_t) CastDoubleToLong(floor(max.x-min.x+0.5));
643- geometry.height=(size_t) CastDoubleToLong(floor(max.y-min.y+0.5));
644+ geometry.x=CastDoubleToSSizeT(ceil(min.x-0.5));
645+ geometry.y=CastDoubleToSSizeT(ceil(min.y-0.5));
646+ geometry.width=(size_t) CastDoubleToSSizeT(floor(max.x-min.x+0.5));
647+ geometry.height=(size_t) CastDoubleToSSizeT(floor(max.y-min.y+0.5));
648 page=(*image)->page;
649 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
650 crop_image=CropImage(*image,&geometry,exception);
651@@ -1217,7 +1217,7 @@ static MagickBooleanType XShearImage(Image *image,const double degrees,
652 displacement*=(-1.0);
653 direction=LEFT;
654 }
655- step=CastDoubleToLong(floor((double) displacement));
656+ step=CastDoubleToSSizeT(floor((double) displacement));
657 area=(double) (displacement-step);
658 step++;
659 pixel=background;
660@@ -1434,7 +1434,7 @@ static MagickBooleanType YShearImage(Image *image,const double degrees,
661 displacement*=(-1.0);
662 direction=UP;
663 }
664- step=CastDoubleToLong(floor((double) displacement));
665+ step=CastDoubleToSSizeT(floor((double) displacement));
666 area=(double) (displacement-step);
667 step++;
668 pixel=background;
669@@ -1617,11 +1617,11 @@ MagickExport Image *ShearImage(const Image *image,const double x_shear,
670 /*
671 Compute image size.
672 */
673- bounds.width=image->columns+CastDoubleToLong(floor(fabs(shear.x)*
674+ bounds.width=image->columns+CastDoubleToSSizeT(floor(fabs(shear.x)*
675 image->rows+0.5));
676- bounds.x=CastDoubleToLong(ceil((double) image->columns+((fabs(shear.x)*
677+ bounds.x=CastDoubleToSSizeT(ceil((double) image->columns+((fabs(shear.x)*
678 image->rows)-image->columns)/2.0-0.5));
679- bounds.y=CastDoubleToLong(ceil((double) image->rows+((fabs(shear.y)*
680+ bounds.y=CastDoubleToSSizeT(ceil((double) image->rows+((fabs(shear.y)*
681 bounds.width)-image->rows)/2.0-0.5));
682 /*
683 Surround image with border.
684@@ -1770,9 +1770,9 @@ MagickExport Image *ShearRotateImage(const Image *image,const double degrees,
685 bounds.height=(size_t) floor(fabs((double) bounds.width*shear.y)+height+0.5);
686 shear_width=(size_t) floor(fabs((double) bounds.height*shear.x)+
687 bounds.width+0.5);
688- bounds.x=CastDoubleToLong(floor((double) ((shear_width > bounds.width) ?
689+ bounds.x=CastDoubleToSSizeT(floor((double) ((shear_width > bounds.width) ?
690 width : bounds.width-shear_width+2)/2.0+0.5));
691- bounds.y=CastDoubleToLong(floor(((double) bounds.height-height+2)/2.0+0.5));
692+ bounds.y=CastDoubleToSSizeT(floor(((double) bounds.height-height+2)/2.0+0.5));
693 /*
694 Surround image with a border.
695 */
696diff --git a/MagickCore/studio.h b/MagickCore/studio.h
697index fbdcc2d00..a0e8a9a1a 100644
698--- a/MagickCore/studio.h
699+++ b/MagickCore/studio.h
700@@ -350,8 +350,6 @@ extern int vsnprintf(char *,size_t,const char *,va_list);
701 Magick defines.
702 */
703 #define MagickMaxRecursionDepth 600
704-#define MAGICK_SSIZE_MAX (SSIZE_MAX)
705-#define MAGICK_SSIZE_MIN (-(SSIZE_MAX)-1)
706 #define Swap(x,y) ((x)^=(y), (y)^=(x), (x)^=(y))
707 #if defined(_MSC_VER)
708 # define DisableMSCWarning(nr) __pragma(warning(push)) \
709diff --git a/MagickCore/transform.c b/MagickCore/transform.c
710index 385d5eb68..6afe0a3de 100644
711--- a/MagickCore/transform.c
712+++ b/MagickCore/transform.c
713@@ -773,8 +773,8 @@ static inline ssize_t PixelRoundOffset(double x)
714 Round the fraction to nearest integer.
715 */
716 if ((x-floor(x)) < (ceil(x)-x))
717- return(CastDoubleToLong(floor(x)));
718- return(CastDoubleToLong(ceil(x)));
719+ return(CastDoubleToSSizeT(floor(x)));
720+ return(CastDoubleToSSizeT(ceil(x)));
721 }
722
723 MagickExport Image *CropImageToTiles(const Image *image,
724diff --git a/MagickCore/visual-effects.c b/MagickCore/visual-effects.c
725index 789660231..069904a08 100644
726--- a/MagickCore/visual-effects.c
727+++ b/MagickCore/visual-effects.c
728@@ -1439,8 +1439,8 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
729 */
730 depth--;
731 attenuate++;
732- x_mid=CastDoubleToLong(ceil((segment->x1+segment->x2)/2-0.5));
733- y_mid=CastDoubleToLong(ceil((segment->y1+segment->y2)/2-0.5));
734+ x_mid=CastDoubleToSSizeT(ceil((segment->x1+segment->x2)/2-0.5));
735+ y_mid=CastDoubleToSSizeT(ceil((segment->y1+segment->y2)/2-0.5));
736 local_info=(*segment);
737 local_info.x2=(double) x_mid;
738 local_info.y2=(double) y_mid;
739@@ -1463,8 +1463,8 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
740 &local_info,attenuate,depth,exception);
741 return(status == 0 ? MagickFalse : MagickTrue);
742 }
743- x_mid=CastDoubleToLong(ceil((segment->x1+segment->x2)/2-0.5));
744- y_mid=CastDoubleToLong(ceil((segment->y1+segment->y2)/2-0.5));
745+ x_mid=CastDoubleToSSizeT(ceil((segment->x1+segment->x2)/2-0.5));
746+ y_mid=CastDoubleToSSizeT(ceil((segment->y1+segment->y2)/2-0.5));
747 if ((fabs(segment->x1-x_mid) < MagickEpsilon) &&
748 (fabs(segment->x2-x_mid) < MagickEpsilon) &&
749 (fabs(segment->y1-y_mid) < MagickEpsilon) &&
750@@ -1481,10 +1481,10 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
751 /*
752 Left pixel.
753 */
754- x=CastDoubleToLong(ceil(segment->x1-0.5));
755- u=GetCacheViewVirtualPixels(u_view,x,CastDoubleToLong(ceil(
756+ x=CastDoubleToSSizeT(ceil(segment->x1-0.5));
757+ u=GetCacheViewVirtualPixels(u_view,x,CastDoubleToSSizeT(ceil(
758 segment->y1-0.5)),1,1,exception);
759- v=GetCacheViewVirtualPixels(v_view,x,CastDoubleToLong(ceil(
760+ v=GetCacheViewVirtualPixels(v_view,x,CastDoubleToSSizeT(ceil(
761 segment->y2-0.5)),1,1,exception);
762 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
763 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
764@@ -1504,10 +1504,10 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
765 /*
766 Right pixel.
767 */
768- x=CastDoubleToLong(ceil(segment->x2-0.5));
769- u=GetCacheViewVirtualPixels(u_view,x,CastDoubleToLong(ceil(
770+ x=CastDoubleToSSizeT(ceil(segment->x2-0.5));
771+ u=GetCacheViewVirtualPixels(u_view,x,CastDoubleToSSizeT(ceil(
772 segment->y1-0.5)),1,1,exception);
773- v=GetCacheViewVirtualPixels(v_view,x,CastDoubleToLong(ceil(
774+ v=GetCacheViewVirtualPixels(v_view,x,CastDoubleToSSizeT(ceil(
775 segment->y2-0.5)),1,1,exception);
776 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
777 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
778@@ -1533,10 +1533,10 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
779 /*
780 Bottom pixel.
781 */
782- y=CastDoubleToLong(ceil(segment->y2-0.5));
783- u=GetCacheViewVirtualPixels(u_view,CastDoubleToLong(ceil(
784+ y=CastDoubleToSSizeT(ceil(segment->y2-0.5));
785+ u=GetCacheViewVirtualPixels(u_view,CastDoubleToSSizeT(ceil(
786 segment->x1-0.5)),y,1,1,exception);
787- v=GetCacheViewVirtualPixels(v_view,CastDoubleToLong(ceil(
788+ v=GetCacheViewVirtualPixels(v_view,CastDoubleToSSizeT(ceil(
789 segment->x2-0.5)),y,1,1,exception);
790 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
791 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
792@@ -1557,10 +1557,10 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
793 /*
794 Top pixel.
795 */
796- y=CastDoubleToLong(ceil(segment->y1-0.5));
797- u=GetCacheViewVirtualPixels(u_view,CastDoubleToLong(ceil(
798+ y=CastDoubleToSSizeT(ceil(segment->y1-0.5));
799+ u=GetCacheViewVirtualPixels(u_view,CastDoubleToSSizeT(ceil(
800 segment->x1-0.5)),y,1,1,exception);
801- v=GetCacheViewVirtualPixels(v_view,CastDoubleToLong(ceil(
802+ v=GetCacheViewVirtualPixels(v_view,CastDoubleToSSizeT(ceil(
803 segment->x2-0.5)),y,1,1,exception);
804 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
805 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
806@@ -1583,11 +1583,11 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
807 /*
808 Middle pixel.
809 */
810- x=CastDoubleToLong(ceil(segment->x1-0.5));
811- y=CastDoubleToLong(ceil(segment->y1-0.5));
812+ x=CastDoubleToSSizeT(ceil(segment->x1-0.5));
813+ y=CastDoubleToSSizeT(ceil(segment->y1-0.5));
814 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
815- x=CastDoubleToLong(ceil(segment->x2-0.5));
816- y=CastDoubleToLong(ceil(segment->y2-0.5));
817+ x=CastDoubleToSSizeT(ceil(segment->x2-0.5));
818+ y=CastDoubleToSSizeT(ceil(segment->y2-0.5));
819 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
820 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
821 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
822diff --git a/MagickWand/drawing-wand.c b/MagickWand/drawing-wand.c
823index cc1fbc640..002798ba0 100644
824--- a/MagickWand/drawing-wand.c
825+++ b/MagickWand/drawing-wand.c
826@@ -4285,10 +4285,10 @@ WandExport MagickBooleanType DrawPushPattern(DrawingWand *wand,
827 x,y,width,height);
828 wand->indent_depth++;
829 wand->pattern_id=AcquireString(pattern_id);
830- wand->pattern_bounds.x=CastDoubleToLong(ceil(x-0.5));
831- wand->pattern_bounds.y=CastDoubleToLong(ceil(y-0.5));
832- wand->pattern_bounds.width=(size_t) CastDoubleToLong(floor(width+0.5));
833- wand->pattern_bounds.height=(size_t) CastDoubleToLong(floor(height+0.5));
834+ wand->pattern_bounds.x=CastDoubleToSSizeT(ceil(x-0.5));
835+ wand->pattern_bounds.y=CastDoubleToSSizeT(ceil(y-0.5));
836+ wand->pattern_bounds.width=(size_t) CastDoubleToSSizeT(floor(width+0.5));
837+ wand->pattern_bounds.height=(size_t) CastDoubleToSSizeT(floor(height+0.5));
838 wand->pattern_offset=wand->mvg_length;
839 return(MagickTrue);
840 }
841diff --git a/MagickWand/studio.h b/MagickWand/studio.h
842index 3dcb4d304..4daf7e894 100644
843--- a/MagickWand/studio.h
844+++ b/MagickWand/studio.h
845@@ -305,8 +305,6 @@ extern int vsnprintf(char *,size_t,const char *,va_list);
846 /*
847 Magick defines.
848 */
849-#define MAGICK_SSIZE_MAX (SSIZE_MAX)
850-#define MAGICK_SSIZE_MIN (-(SSIZE_MAX)-1)
851 #if defined(_MSC_VER)
852 # define DisableMSCWarning(nr) __pragma(warning(push)) \
853 __pragma(warning(disable:nr))
854diff --git a/coders/histogram.c b/coders/histogram.c
855index 0df364c12..15ee9772d 100644
856--- a/coders/histogram.c
857+++ b/coders/histogram.c
858@@ -295,7 +295,7 @@ static MagickBooleanType WriteHISTOGRAMImage(const ImageInfo *image_info,
859 break;
860 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
861 {
862- y=CastDoubleToLong(ceil((double) histogram_image->rows-scale*
863+ y=CastDoubleToSSizeT(ceil((double) histogram_image->rows-scale*
864 histogram[x].red-0.5));
865 r=q+y*GetPixelChannels(histogram_image);
866 for ( ; y < (ssize_t) histogram_image->rows; y++)
867@@ -306,7 +306,7 @@ static MagickBooleanType WriteHISTOGRAMImage(const ImageInfo *image_info,
868 }
869 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
870 {
871- y=CastDoubleToLong(ceil((double) histogram_image->rows-scale*
872+ y=CastDoubleToSSizeT(ceil((double) histogram_image->rows-scale*
873 histogram[x].green-0.5));
874 r=q+y*GetPixelChannels(histogram_image);
875 for ( ; y < (ssize_t) histogram_image->rows; y++)
876@@ -317,7 +317,7 @@ static MagickBooleanType WriteHISTOGRAMImage(const ImageInfo *image_info,
877 }
878 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
879 {
880- y=CastDoubleToLong(ceil((double) histogram_image->rows-scale*
881+ y=CastDoubleToSSizeT(ceil((double) histogram_image->rows-scale*
882 histogram[x].blue-0.5));
883 r=q+y*GetPixelChannels(histogram_image);
884 for ( ; y < (ssize_t) histogram_image->rows; y++)
885diff --git a/coders/jpeg.c b/coders/jpeg.c
886index db385358b..d779644ab 100644
887--- a/coders/jpeg.c
888+++ b/coders/jpeg.c
889@@ -2325,7 +2325,8 @@ static MagickBooleanType WriteJPEGImage_(const ImageInfo *image_info,
890 if (image->debug != MagickFalse)
891 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
892 "Image resolution: %.20g,%.20g",image->resolution.x,image->resolution.y);
893- if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
894+ if ((image->resolution.x >= 0) && (image->resolution.x < (double) SHRT_MAX) &&
895+ (image->resolution.y >= 0) && (image->resolution.y < (double) SHRT_MAX))
896 {
897 /*
898 Set image resolution.
899diff --git a/coders/png.c b/coders/png.c
900index e730edb03..6f88e9cdc 100644
901--- a/coders/png.c
902+++ b/coders/png.c
903@@ -10020,23 +10020,23 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
904 {
905 ping_pHYs_unit_type=PNG_RESOLUTION_METER;
906 ping_pHYs_x_resolution=
907- (png_uint_32) ((100.0*image->resolution.x+0.5)/2.54);
908+ (png_uint_32) CastDoubleToSizeT((100.0*image->resolution.x+0.5)/2.54);
909 ping_pHYs_y_resolution=
910- (png_uint_32) ((100.0*image->resolution.y+0.5)/2.54);
911+ (png_uint_32) CastDoubleToSizeT((100.0*image->resolution.y+0.5)/2.54);
912 }
913
914 else if (image->units == PixelsPerCentimeterResolution)
915 {
916 ping_pHYs_unit_type=PNG_RESOLUTION_METER;
917- ping_pHYs_x_resolution=(png_uint_32) (100.0*image->resolution.x+0.5);
918- ping_pHYs_y_resolution=(png_uint_32) (100.0*image->resolution.y+0.5);
919+ ping_pHYs_x_resolution=(png_uint_32) CastDoubleToSizeT(100.0*image->resolution.x+0.5);
920+ ping_pHYs_y_resolution=(png_uint_32) CastDoubleToSizeT(100.0*image->resolution.y+0.5);
921 }
922
923 else
924 {
925 ping_pHYs_unit_type=PNG_RESOLUTION_UNKNOWN;
926- ping_pHYs_x_resolution=(png_uint_32) image->resolution.x;
927- ping_pHYs_y_resolution=(png_uint_32) image->resolution.y;
928+ ping_pHYs_x_resolution=(png_uint_32) CastDoubleToSizeT(image->resolution.x);
929+ ping_pHYs_y_resolution=(png_uint_32) CastDoubleToSizeT(image->resolution.y);
930 }
931
932 if (logging != MagickFalse)
933diff --git a/coders/tiff.c b/coders/tiff.c
934index 68a6d5b09..a0bdd6313 100644
935--- a/coders/tiff.c
936+++ b/coders/tiff.c
937@@ -1506,9 +1506,9 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
938 if ((TIFFGetFieldDefaulted(tiff,TIFFTAG_XPOSITION,&x_position,sans) == 1) &&
939 (TIFFGetFieldDefaulted(tiff,TIFFTAG_YPOSITION,&y_position,sans) == 1))
940 {
941- image->page.x=CastDoubleToLong(ceil(x_position*
942+ image->page.x=CastDoubleToSSizeT(ceil(x_position*
943 image->resolution.x-0.5));
944- image->page.y=CastDoubleToLong(ceil(y_position*
945+ image->page.y=CastDoubleToSSizeT(ceil(y_position*
946 image->resolution.y-0.5));
947 }
948 if (TIFFGetFieldDefaulted(tiff,TIFFTAG_ORIENTATION,&orientation,sans) == 1)
949diff --git a/coders/txt.c b/coders/txt.c
950index f8312a4fd..91323583d 100644
951--- a/coders/txt.c
952+++ b/coders/txt.c
953@@ -273,7 +273,7 @@ static Image *ReadTEXTImage(const ImageInfo *image_info,
954 draw_info=DestroyDrawInfo(draw_info);
955 ThrowReaderException(TypeError,"UnableToGetTypeMetrics");
956 }
957- page.y=CastDoubleToLong(ceil((double) page.y+metrics.ascent-0.5));
958+ page.y=CastDoubleToSSizeT(ceil((double) page.y+metrics.ascent-0.5));
959 (void) FormatLocaleString(geometry,MagickPathExtent,"%gx%g%+g%+g",(double)
960 image->columns,(double) image->rows,(double) page.x,(double) page.y);
961 (void) CloneString(&draw_info->geometry,geometry);
962@@ -574,7 +574,7 @@ static Image *ReadTXTImage(const ImageInfo *image_info,ExceptionInfo *exception)
963 black),range);
964 pixel.alpha=(MagickRealType) ScaleAnyToQuantum(CastDoubleToQuantumAny(
965 alpha),range);
966- q=GetAuthenticPixels(image,CastDoubleToLong(x_offset),CastDoubleToLong(
967+ q=GetAuthenticPixels(image,CastDoubleToSSizeT(x_offset),CastDoubleToSSizeT(
968 y_offset),1,1,exception);
969 if (q == (Quantum *) NULL)
970 {
971--
9722.34.1
973