From 6f4e6ab0e4dd78460e04aca3c8f38bbf8de837b5 Mon Sep 17 00:00:00 2001
From: wang_yue111 <648774160@qq.com>
Date: Wed, 3 Mar 2021 11:01:31 +0800
Subject: [PATCH] https://github.com/ImageMagick/ImageMagick/issues/1751

---
 magick/quantum-private.h | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/magick/quantum-private.h b/magick/quantum-private.h
index 7d51397..d4b0143 100644
--- a/magick/quantum-private.h
+++ b/magick/quantum-private.h
@@ -327,7 +327,7 @@ static inline QuantumAny ScaleQuantumToAny(const Quantum quantum,
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
   return((QuantumAny) ((MagickRealType) range*quantum/QuantumRange));
 #else
-  if (quantum <= 0.0)
+  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
     return((QuantumAny) 0UL);
   if (((MagickRealType) range*quantum/QuantumRange) >= 18446744073709551615.0)
     return((QuantumAny) MagickULLConstant(18446744073709551615));
@@ -368,8 +368,8 @@ static inline unsigned int ScaleQuantumToLong(const Quantum quantum)
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
   return((unsigned int) (16843009UL*quantum));
 #else
-  if (quantum <= 0.0)
-    return(0UL);
+  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
+    return(0U);
   if ((16843009.0*quantum) >= 4294967295.0)
     return(4294967295UL);
   return((unsigned int) (16843009.0*quantum+0.5));
@@ -383,8 +383,8 @@ static inline unsigned int ScaleQuantumToMap(const Quantum quantum)
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
   return((unsigned int) quantum);
 #else
-  if (quantum < 0.0)
-    return(0UL);
+  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
+    return(0U);
   return((unsigned int) (quantum+0.5));
 #endif
 }
@@ -394,7 +394,7 @@ static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
   return((unsigned short) (257UL*quantum));
 #else
-  if (quantum <= 0.0)
+  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
     return(0);
   if ((257.0*quantum) >= 65535.0)
     return(65535);
@@ -447,8 +447,8 @@ static inline unsigned int ScaleQuantumToLong(const Quantum quantum)
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
   return((unsigned int) (65537UL*quantum));
 #else
-  if (quantum <= 0.0)
-    return(0UL);
+  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
+    return(0U);
   if ((65537.0*quantum) >= 4294967295.0)
     return(4294967295U);
   return((unsigned int) (65537.0*quantum+0.5));
@@ -462,8 +462,8 @@ static inline unsigned int ScaleQuantumToMap(const Quantum quantum)
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
   return((unsigned int) quantum);
 #else
-  if (quantum < 0.0)
-    return(0UL);
+  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
+    return(0U);
   return((unsigned int) (quantum+0.5));
 #endif
 }
@@ -473,7 +473,7 @@ static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
   return((unsigned short) quantum);
 #else
-  if (quantum <= 0.0)
+  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
     return(0);
   if (quantum >= 65535.0)
     return(65535);
@@ -518,8 +518,8 @@ static inline unsigned int ScaleQuantumToLong(const Quantum quantum)
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
   return((unsigned int) quantum);
 #else
-  if (quantum <= 0.0)
-    return(0);
+  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
+    return(0U);
   if ((quantum) >= 4294967295.0)
     return(4294967295);
   return((unsigned int) (quantum+0.5));
@@ -528,8 +528,8 @@ static inline unsigned int ScaleQuantumToLong(const Quantum quantum)
 
 static inline unsigned int ScaleQuantumToMap(const Quantum quantum)
 {
-  if (quantum < 0.0)
-    return(0UL);
+  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
+    return(0U);
   if ((quantum/65537) >= (Quantum) MaxMap)
     return((unsigned int) MaxMap);
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
@@ -546,7 +546,7 @@ static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
   return((unsigned short) ((quantum+MagickULLConstant(32768))/
     MagickULLConstant(65537)));
 #else
-  if (quantum <= 0.0)
+  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
     return(0);
   if ((quantum/65537.0) >= 65535.0)
     return(65535);
@@ -589,8 +589,8 @@ static inline unsigned int ScaleQuantumToLong(const Quantum quantum)
 
 static inline unsigned int ScaleQuantumToMap(const Quantum quantum)
 {
-  if (quantum <= 0.0)
-    return(0UL);
+  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
+    return(0U);
   if ((quantum/281479271743489.0) >= MaxMap)
     return((unsigned int) MaxMap);
   return((unsigned int) (quantum/281479271743489.0+0.5));
@@ -598,7 +598,7 @@ static inline unsigned int ScaleQuantumToMap(const Quantum quantum)
 
 static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
 {
-  if (quantum <= 0.0)
+  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
     return(0);
   if ((quantum/281479271743489.0) >= 65535.0)
     return(65535);
-- 
2.23.0

