Commit 68d36a371 for imagemagick.org

commit 68d36a371840c0be81286f95d95e05ba3572f9f1
Author: Cristy <urban-warrior@imagemagick.org>
Date:   Fri Dec 4 19:04:48 2026 -0500

    ReadFL32Image reads files with more than four channels as MultispectralQuantum

diff --git a/coders/fl32.c b/coders/fl32.c
index 1e26dd7a0..46692edb5 100644
--- a/coders/fl32.c
+++ b/coders/fl32.c
@@ -146,6 +146,7 @@ static Image *ReadFL32Image(const ImageInfo *image_info,
     quantum_type;

   size_t
+    channels,
     extent;

   ssize_t
@@ -182,12 +183,11 @@ static Image *ReadFL32Image(const ImageInfo *image_info,
   image->endian=LSBEndian;
   image->rows=(size_t) ReadBlobLSBLong(image);
   image->columns=(size_t) ReadBlobLSBLong(image);
-  image->number_channels=(size_t) ReadBlobLSBLong(image);
-  if ((image->columns == 0) || (image->rows == 0) ||
-      (image->number_channels == 0) ||
-      (image->number_channels >= MaxPixelChannels))
+  channels=(size_t) ReadBlobLSBLong(image);
+  if ((EOFBlob(image) != MagickFalse) || (image->columns == 0) ||
+      (image->rows == 0) || (channels == 0) || (channels >= MaxPixelChannels))
     ThrowReaderException(CorruptImageError,"ImproperImageHeader");
-  switch (image->number_channels)
+  switch (channels)
   {
     case 1:
     {
@@ -217,8 +217,14 @@ static Image *ReadFL32Image(const ImageInfo *image_info,
     }
     default:
     {
-      image->number_meta_channels=image->number_channels-3;
-      quantum_type=RGBQuantum;
+      /*
+        RGB plus meta channels: every channel is stored per pixel, so the
+        row must be read as multispectral data, not as 3-channel RGB.
+      */
+      image->colorspace=sRGBColorspace;
+      if (SetPixelMetaChannels(image,channels-3,exception) == MagickFalse)
+        return(DestroyImageList(image));
+      quantum_type=MultispectralQuantum;
       break;
     }
   }
@@ -236,8 +242,17 @@ static Image *ReadFL32Image(const ImageInfo *image_info,
   quantum_info=AcquireQuantumInfo(image_info,image);
   if (quantum_info == (QuantumInfo *) NULL)
     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
-  status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);
+  if (SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat) == MagickFalse)
+    {
+      quantum_info=DestroyQuantumInfo(quantum_info);
+      ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+    }
   extent=GetQuantumExtent(image,quantum_info,quantum_type);
+  if (extent != (image->columns*channels*sizeof(float)))
+    {
+      quantum_info=DestroyQuantumInfo(quantum_info);
+      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+    }
   pixels=GetQuantumPixels(quantum_info);
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -403,6 +418,9 @@ static MagickBooleanType WriteFL32Image(const ImageInfo *image_info,
   status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
   if (status == MagickFalse)
     return(status);
+  if (((MagickSizeType) image->columns > 0xFFFFFFFFUL) ||
+      ((MagickSizeType) image->rows > 0xFFFFFFFFUL))
+    ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
   if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
     (void) TransformImageColorspace(image,sRGBColorspace,exception);
   (void) WriteBlobLSBLong(image,842222662U);
@@ -450,8 +468,12 @@ static MagickBooleanType WriteFL32Image(const ImageInfo *image_info,
   (void) WriteBlobLSBLong(image,(unsigned int) channels);
   quantum_info=AcquireQuantumInfo(image_info,image);
   if (quantum_info == (QuantumInfo *) NULL)
-    ThrowWriterException(ImageError,"MemoryAllocationFailed");
-  status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);
+    ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+  if (SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat) == MagickFalse)
+    {
+      quantum_info=DestroyQuantumInfo(quantum_info);
+      ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+    }
   pixels=(unsigned char *) GetQuantumPixels(quantum_info);
   for (y=0; y < (ssize_t) image->rows; y++)
   {