Commit 6fcb78e4a for imagemagick.org
commit 6fcb78e4af2e94e9fb3011b5f5540c22cd44015b
Author: Cristy <urban-warrior@imagemagick.org>
Date: Fri Dec 4 17:51:15 2026 -0500
pixel bytes are now checked for end of file.
diff --git a/coders/pix.c b/coders/pix.c
index 0ed285d89..6bb41b207 100644
--- a/coders/pix.c
+++ b/coders/pix.c
@@ -187,12 +187,29 @@ static Image *ReadPIXImage(const ImageInfo *image_info,ExceptionInfo *exception)
break;
length=(size_t) c;
if (bits_per_pixel == 8)
- index=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
+ {
+ c=ReadBlobByte(image);
+ if (c == EOF)
+ break;
+ /*
+ The colormap is a 256-entry gray ramp: the index is the raw
+ byte, not a scaled quantum (which overflows it in Q16/HDRI).
+ */
+ index=(Quantum) c;
+ red=ScaleCharToQuantum((unsigned char) c);
+ green=red;
+ blue=red;
+ }
else
{
- blue=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
- green=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
- red=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
+ unsigned char
+ pixel[3];
+
+ if (ReadBlob(image,3,pixel) != 3)
+ break;
+ blue=ScaleCharToQuantum(pixel[0]);
+ green=ScaleCharToQuantum(pixel[1]);
+ red=ScaleCharToQuantum(pixel[2]);
}
}
if (image->storage_class == PseudoClass)
@@ -215,6 +232,8 @@ static Image *ReadPIXImage(const ImageInfo *image_info,ExceptionInfo *exception)
break;
}
}
+ if (status == MagickFalse)
+ break;
if (image->storage_class == PseudoClass)
(void) SyncImage(image,exception);
if (EOFBlob(image) != MagickFalse)
@@ -223,19 +242,32 @@ static Image *ReadPIXImage(const ImageInfo *image_info,ExceptionInfo *exception)
image->filename);
break;
}
+ if (y < (ssize_t) image->rows)
+ {
+ ThrowFileException(exception,CorruptImageWarning,
+ "InsufficientImageDataInFile",image->filename);
+ break;
+ }
/*
Proceed to next image.
*/
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
- width=ReadBlobMSBLong(image);
- height=ReadBlobMSBLong(image);
- (void) ReadBlobMSBShort(image);
- (void) ReadBlobMSBShort(image);
+ width=ReadBlobMSBShort(image);
+ height=ReadBlobMSBShort(image);
+ (void) ReadBlobMSBShort(image); /* x-offset */
+ (void) ReadBlobMSBShort(image); /* y-offset */
bits_per_pixel=ReadBlobMSBShort(image);
- status=(width != 0UL) && (height == 0UL) && ((bits_per_pixel == 8) ||
+ if (EOFBlob(image) != MagickFalse)
+ break;
+ status=(width != 0UL) && (height != 0UL) && ((bits_per_pixel == 8) ||
(bits_per_pixel == 24)) ? MagickTrue : MagickFalse;
+ if (status == MagickFalse)
+ {
+ status=MagickTrue; /* trailing data is not a frame; keep what we have */
+ break;
+ }
if (status != MagickFalse)
{
/*