Commit f94a6e70d for imagemagick.org
commit f94a6e70dbcbb8ed33485263e81e055707890ca3
Author: Naveed Khan <164054284+rootvector2@users.noreply.github.com>
Date: Sat Nov 7 19:55:46 2026 +0530
clamp ScaleQuantumToAny at 64-bit depth in non-HDRI builds (#9101)
diff --git a/MagickCore/quantum-private.h b/MagickCore/quantum-private.h
index 777cf2d1f..d1397cb07 100644
--- a/MagickCore/quantum-private.h
+++ b/MagickCore/quantum-private.h
@@ -347,6 +347,8 @@ static inline QuantumAny ScaleQuantumToAny(const Quantum quantum,
const QuantumAny range)
{
#if !defined(MAGICKCORE_HDRI_SUPPORT)
+ if (((double) range*quantum/QuantumRange) >= 18446744073709551615.0)
+ return((QuantumAny) MagickULLConstant(18446744073709551615));
return((QuantumAny) ((double) range*quantum/QuantumRange));
#else
if ((IsNaN(quantum) != 0) || (quantum <= 0.0f))
diff --git a/tests/cli-pipe.tap b/tests/cli-pipe.tap
index bbac0a42c..906f0f059 100755
--- a/tests/cli-pipe.tap
+++ b/tests/cli-pipe.tap
@@ -18,7 +18,7 @@
#
. ./common.shi
. ${srcdir}/tests/common.shi
-echo "1..26"
+echo "1..27"
${MAGICK} pnm:- null: < ${SRCDIR}/rose.pnm && echo "ok" || echo "not ok"
${MAGICK} pnm:- info: < ${SRCDIR}/rose.pnm && echo "ok" || echo "not ok"
@@ -161,4 +161,13 @@ if [ "X$roundtrip" = 'Xgray(255)|gray(0)' ]; then
else
echo "not ok 26 - one-bit PAM writer round trip: $roundtrip"
fi
+
+# A full-range sample exported at 64 bits per sample must stay full range.
+sample=`LC_ALL=C ${MAGICK} -size 1x1 xc:white -depth 64 GRAY:- 2>/dev/null |
+ od -An -tx1 | tr -d ' \n'`
+if [ "X$sample" = 'Xffffffffffffffff' ]; then
+ echo "ok 27 - 64-bit raw export of a full-range sample"
+else
+ echo "not ok 27 - 64-bit raw export of a full-range sample: $sample"
+fi
: