From: Dirk Lemstra Date: Sun, 14 Jan 2018 00:55:04 +0000 (+0100) Subject: Added check to avoid division by zero. X-Git-Tag: 7.0.7-22~81 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=de8b85c78e7cf98debe7ab991d8eae2f9ed0611c;p=imagemagick Added check to avoid division by zero. Credit to OSS-Fuzz --- diff --git a/MagickCore/enhance.c b/MagickCore/enhance.c index bfabe7f4d..3e22fbd87 100644 --- a/MagickCore/enhance.c +++ b/MagickCore/enhance.c @@ -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);