File ImageMagick-CVE-2020-27759,27769,27754.patch of Package ImageMagick.23974

Index: ImageMagick-6.8.8-1/magick/quantize.c
===================================================================
--- ImageMagick-6.8.8-1.orig/magick/quantize.c	2020-12-07 12:32:13.949045444 +0100
+++ ImageMagick-6.8.8-1/magick/quantize.c	2020-12-07 12:33:35.525569903 +0100
@@ -2299,9 +2299,8 @@ MagickExport MagickBooleanType Posterize
   const ChannelType channel,const size_t levels,const MagickBooleanType dither)
 {
 #define PosterizeImageTag  "Posterize/Image"
-#define PosterizePixel(pixel) (Quantum) (QuantumRange*(MagickRound( \
-  QuantumScale*pixel*(levels-1)))/MagickMax((ssize_t) levels-1,1))
-
+#define PosterizePixel(pixel) ClampToQuantum((MagickRealType) QuantumRange*( \
+  MagickRound(QuantumScale*pixel*(levels-1)))/MagickMax((ssize_t) levels-1,1))
   CacheView
     *image_view;
 
@@ -3288,16 +3287,20 @@ extern "C" {
 
 static int IntensityCompare(const void *x,const void *y)
 {
+  double
+    intensity;
+
   PixelPacket
     *color_1,
     *color_2;
 
-  int
-    intensity;
-
   color_1=(PixelPacket *) x;
   color_2=(PixelPacket *) y;
-  intensity=PixelPacketIntensity(color_1)-(int) PixelPacketIntensity(color_2);
+  intensity=PixelPacketIntensity(color_1)-PixelPacketIntensity(color_2);
+  if (intensity < (double) INT_MIN)
+    intensity=(double) INT_MIN;
+  if (intensity > (double) INT_MAX)
+    intensity=(double) INT_MAX;
   return((int) intensity);
 }
 
openSUSE Build Service is sponsored by