From de8b85c78e7cf98debe7ab991d8eae2f9ed0611c Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sun, 14 Jan 2018 01:55:04 +0100 Subject: [PATCH] Added check to avoid division by zero. Credit to OSS-Fuzz --- MagickCore/enhance.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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); -- 2.40.0