From 75f6f5032690077cae3eaeda3c0165cc765eaeb5 Mon Sep 17 00:00:00 2001
From: Cristy <mikayla-grace@urban-warrior.org>
Date: Thu, 25 Feb 2021 19:31:37 -0500
Subject: [PATCH] https://github.com/ImageMagick/ImageMagick/issues/3295

CVE: CVE-2021-20310
Upstream-Status: Backport [https://github.com/ImageMagick/ImageMagick/commit/75f6f5032690077cae3eaeda3c0165cc765eaeb5.patch]
Signed-off-by: Sana Kazi Sana.Kazi@kpit.com
---
 MagickCore/colorspace.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/MagickCore/colorspace.c b/MagickCore/colorspace.c
index e3b7df339f6..9c5ea11e300 100644
--- a/MagickCore/colorspace.c
+++ b/MagickCore/colorspace.c
@@ -329,11 +329,11 @@ static void inline ConvertXYZToJzazbz(const double X,const double Y,
   L=0.41478972*Xp+0.579999*Yp+0.0146480*Zp;
   M=(-0.2015100)*Xp+1.120649*Yp+0.0531008*Zp;
   S=(-0.0166008)*Xp+0.264800*Yp+0.6684799*Zp;
-  gamma=pow(L/white_luminance,Jzazbz_n);
+  gamma=pow(L*PerceptibleReciprocal(white_luminance),Jzazbz_n);
   Lp=pow((Jzazbz_c1+Jzazbz_c2*gamma)/(1.0+Jzazbz_c3*gamma),Jzazbz_p);
-  gamma=pow(M/white_luminance,Jzazbz_n);
+  gamma=pow(M*PerceptibleReciprocal(white_luminance),Jzazbz_n);
   Mp=pow((Jzazbz_c1+Jzazbz_c2*gamma)/(1.0+Jzazbz_c3*gamma),Jzazbz_p);
-  gamma=pow(S/white_luminance,Jzazbz_n);
+  gamma=pow(S*PerceptibleReciprocal(white_luminance),Jzazbz_n);
   Sp=pow((Jzazbz_c1+Jzazbz_c2*gamma)/(1.0+Jzazbz_c3*gamma),Jzazbz_p);
   Iz=0.5*Lp+0.5*Mp;
   *az=3.52400*Lp-4.066708*Mp+0.542708*Sp+0.5;
