File: 0059-1-2-Prepare-CVE-2023-34151-improved-range-checking.patch

package info (click to toggle)
imagemagick 8%3A6.9.11.60%2Bdfsg-1.6%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 76,816 kB
  • sloc: ansic: 349,503; cpp: 21,804; xml: 11,029; perl: 6,417; sh: 5,877; makefile: 3,042; tcl: 459
file content (39 lines) | stat: -rw-r--r-- 971 bytes parent folder | download | duplicates (2)
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));