1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
From: Cristy <urban-warrior@imagemagick.org>
Date: Sat, 15 Apr 2023 09:44:37 -0400
Subject: [1/2] Prepare CVE-2023-34151 :improved range checking
---
magick/image-private.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/magick/image-private.h b/magick/image-private.h
index e0d616d..09d718b 100644
--- a/magick/image-private.h
+++ b/magick/image-private.h
@@ -61,6 +61,26 @@ static inline ssize_t CastDoubleToLong(const double value)
return((ssize_t) value);
}
+static inline size_t CastDoubleToUnsigned(const double x)
+{
+ if (IsNaN(x) != 0)
+ {
+ errno=ERANGE;
+ return(0);
+ }
+ if (floor(x) > ((double) MAGICK_SSIZE_MAX-1))
+ {
+ errno=ERANGE;
+ return((size_t) MAGICK_SIZE_MAX);
+ }
+ if (ceil(x) < 0.0)
+ {
+ errno=ERANGE;
+ return(0);
+ }
+ return((size_t) x);
+}
+
static inline double DegreesToRadians(const double degrees)
{
return((double) (MagickPI*degrees/180.0));
|