]> granicus.if.org Git - imagemagick/commitdiff
Added check to avoid division by zero.
authorDirk Lemstra <dirk@git.imagemagick.org>
Sun, 14 Jan 2018 00:55:04 +0000 (01:55 +0100)
committerDirk Lemstra <dirk@git.imagemagick.org>
Sun, 14 Jan 2018 00:57:55 +0000 (01:57 +0100)
Credit to OSS-Fuzz

MagickCore/enhance.c

index bfabe7f4d8521a91c817f2d6988ccccb1a66e604..3e22fbd872c29f33e3c0f0560212687997176a40 100644 (file)
@@ -1446,11 +1446,14 @@ MagickExport Image *EnhanceImage(const Image *image,ExceptionInfo *exception)
       r=p+4*GetPixelChannels(image)*(image->columns+4);
       EnhancePixel(5.0); EnhancePixel(8.0); EnhancePixel(10.0);
         EnhancePixel(8.0); EnhancePixel(5.0);
-      pixel.red=((aggregate.red+total_weight/2.0)/total_weight);
-      pixel.green=((aggregate.green+total_weight/2.0)/total_weight);
-      pixel.blue=((aggregate.blue+total_weight/2.0)/total_weight);
-      pixel.black=((aggregate.black+total_weight/2.0)/total_weight);
-      pixel.alpha=((aggregate.alpha+total_weight/2.0)/total_weight);
+      if (total_weight > MagickEpsilon)
+        {
+          pixel.red=((aggregate.red+total_weight/2.0)/total_weight);
+          pixel.green=((aggregate.green+total_weight/2.0)/total_weight);
+          pixel.blue=((aggregate.blue+total_weight/2.0)/total_weight);
+          pixel.black=((aggregate.black+total_weight/2.0)/total_weight);
+          pixel.alpha=((aggregate.alpha+total_weight/2.0)/total_weight);
+        }
       SetPixelViaPixelInfo(image,&pixel,q);
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(enhance_image);