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