File ImageMagick-CVE-2021-20244.patch of Package ImageMagick.30356
From 329dd528ab79531d884c0ba131e97d43f872ab5d Mon Sep 17 00:00:00 2001
From: ruc_zhangxiaohui <553441439@qq.com>
Date: Thu, 4 Feb 2021 04:19:08 +0800
Subject: [PATCH] uses the PerceptibleReciprocal() to prevent the
divide-by-zero from occurring (#3194)
Co-authored-by: Zhang Xiaohui <ruc_zhangxiaohui@163.com>
---
MagickCore/visual-effects.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
Index: ImageMagick-7.0.7-34/MagickCore/fx.c
===================================================================
--- ImageMagick-7.0.7-34.orig/MagickCore/fx.c 2021-02-23 10:45:40.459550190 +0100
+++ ImageMagick-7.0.7-34/MagickCore/fx.c 2021-02-23 10:46:00.135674384 +0100
@@ -3322,11 +3322,11 @@ MagickExport Image *ImplodeImage(const I
center.y=0.5*canvas->rows;
radius=center.x;
if (canvas->columns > canvas->rows)
- scale.y=(double) canvas->columns/(double) canvas->rows;
+ scale.y=(double) canvas->columns*PerceptibleReciprocal((double) canvas->rows);
else
if (canvas->columns < canvas->rows)
{
- scale.x=(double) canvas->rows/(double) canvas->columns;
+ scale.x=(double) canvas->rows*PerceptibleReciprocal((double) canvas->columns);
radius=center.y;
}
/*
@@ -3401,10 +3401,10 @@ MagickExport Image *ImplodeImage(const I
*/
factor=1.0;
if (distance > 0.0)
- factor=pow(sin(MagickPI*sqrt((double) distance)/radius/2),-amount);
+ factor=pow(sin(MagickPI*sqrt((double) distance)*PerceptibleReciprocal(radius)/2),-amount);
status=InterpolatePixelChannels(canvas,interpolate_view,implode_image,
- method,(double) (factor*delta.x/scale.x+center.x),(double) (factor*
- delta.y/scale.y+center.y),q,exception);
+ method,(double) (factor*delta.x*PerceptibleReciprocal(scale.x)+center.x),(double) (factor*
+ delta.y*PerceptibleReciprocal(scale.y)+center.y),q,exception);
if (status == MagickFalse)
break;
}