Commit 8c4ddb2f7 for imagemagick.org
commit 8c4ddb2f7b97b95146d500c31d440f8efe1d9eff
Author: Cristy <urban-warrior@imagemagick.org>
Date: Fri Dec 4 19:00:51 2026 -0500
ReadARTImage now rejects truncated or zero-dimension headers before ping/allocation
diff --git a/coders/art.c b/coders/art.c
index dc5d90cdb..428b1c21b 100644
--- a/coders/art.c
+++ b/coders/art.c
@@ -139,6 +139,12 @@ static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception)
image->columns=(size_t) ReadBlobLSBShort(image);
(void) ReadBlobLSBShort(image);
image->rows=(size_t) ReadBlobLSBShort(image);
+ /*
+ Reject truncated or degenerate headers before ping or allocation.
+ */
+ if ((EOFBlob(image) != MagickFalse) || (image->columns == 0) ||
+ (image->rows == 0))
+ ThrowReaderException(CorruptImageError,"ImproperImageHeader");
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
@@ -150,7 +156,7 @@ static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception)
/*
Convert bi-level image to pixel packets.
*/
- SetImageColorspace(image,GRAYColorspace,exception);
+ (void) SetImageColorspace(image,GRAYColorspace,exception);
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
@@ -172,8 +178,14 @@ static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception)
break;
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GrayQuantum,(unsigned char *) stream,exception);
- stream=ReadBlobStream(image,(size_t) (-(ssize_t) length) & 0x01,pixels,
- &count);
+ if ((length & 0x01) != 0)
+ {
+ /*
+ Rows are padded to an even number of bytes.
+ */
+ if (ReadBlobByte(image) == EOF)
+ break;
+ }
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
@@ -317,7 +329,8 @@ static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image,
status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
if (status == MagickFalse)
return(status);
- if ((image->columns > 65535UL) || (image->rows > 65535UL))
+ if ((image->columns == 0) || (image->rows == 0) ||
+ (image->columns > 65535UL) || (image->rows > 65535UL))
ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace,exception);
@@ -330,7 +343,7 @@ static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image,
(void) WriteBlobLSBShort(image,(unsigned short) image->rows);
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
- ThrowWriterException(ImageError,"MemoryAllocationFailed");
+ ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
pixels=(unsigned char *) GetQuantumPixels(quantum_info);
for (y=0; y < (ssize_t) image->rows; y++)
{
@@ -345,11 +358,16 @@ static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image,
status=MagickFalse;
break;
}
- count=WriteBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
- if (count != (ssize_t) (-(ssize_t) length & 0x01))
+ if ((length & 0x01) != 0)
{
- status=MagickFalse;
- break;
+ /*
+ Pad each row to an even number of bytes.
+ */
+ if (WriteBlobByte(image,0) != 1)
+ {
+ status=MagickFalse;
+ break;
+ }
}
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);