Commit a89f4e452 for imagemagick.org
commit a89f4e45235804c8adf4a0e28ce683d636cc547c
Author: Dirk Lemstra <dirk@lemstra.org>
Date: Sat May 30 15:09:28 2026 +0200
Centralize checking if pinged images have a size that has zero columns or rows and removed redundant checks.
diff --git a/MagickCore/constitute.c b/MagickCore/constitute.c
index e131a8302..bbc8fe196 100644
--- a/MagickCore/constitute.c
+++ b/MagickCore/constitute.c
@@ -316,6 +316,8 @@ MagickExport Image *PingImage(const ImageInfo *image_info,
image=ReadStream(ping_info,&PingStream,exception);
if (image != (Image *) NULL)
{
+ if ((image->columns == 0) || (image->rows == 0))
+ ThrowReaderException(CorruptImageError,"ImproperImageHeader");
ResetTimer(&image->timer);
if (ping_info->verbose != MagickFalse)
(void) IdentifyImage(image,stdout,MagickFalse,exception);
@@ -825,6 +827,17 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
"notify the developers",image->magick,exception->severity);
if (IsBlobTemporary(image) != MagickFalse)
(void) RelinquishUniqueFileResource(read_info->filename);
+ if (read_info->ping != MagickFalse)
+ {
+ for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
+ {
+ if ((image->columns == 0) || (image->rows == 0))
+ {
+ read_info=DestroyImageInfo(read_info);
+ ThrowReaderException(ImageError,"NegativeOrZeroImageSize");
+ }
+ }
+ }
if ((IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
(GetImageListLength(image) != 1))
{
diff --git a/coders/art.c b/coders/art.c
index 3812b31ef..5224fb7e9 100644
--- a/coders/art.c
+++ b/coders/art.c
@@ -139,8 +139,6 @@ static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception)
image->columns=(size_t) ReadBlobLSBShort(image);
(void) ReadBlobLSBShort(image);
image->rows=(size_t) ReadBlobLSBShort(image);
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
diff --git a/coders/cin.c b/coders/cin.c
index ef41814a2..069174a99 100644
--- a/coders/cin.c
+++ b/coders/cin.c
@@ -727,8 +727,6 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
image->rows=cin.image.channel[0].lines_per_image;
if (image_info->ping != MagickFalse)
{
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(void) CloseBlob(image);
return(image);
}
diff --git a/coders/dds.c b/coders/dds.c
index f6f9c8194..329319888 100644
--- a/coders/dds.c
+++ b/coders/dds.c
@@ -3091,11 +3091,7 @@ static Image *ReadDDSImage(const ImageInfo *image_info,ExceptionInfo *exception)
image->endian=LSBEndian;
image->depth=8;
if (image_info->ping != MagickFalse)
- {
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
- continue;
- }
+ continue;
status=SetImageExtent(image,image->columns,image->rows,exception);
if (status == MagickFalse)
return(DestroyImageList(image));
diff --git a/coders/dpx.c b/coders/dpx.c
index 4406fadda..efd5cc31b 100644
--- a/coders/dpx.c
+++ b/coders/dpx.c
@@ -1138,8 +1138,6 @@ static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
}
if (image_info->ping != MagickFalse)
{
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
diff --git a/coders/farbfeld.c b/coders/farbfeld.c
index c73145868..a343ccac6 100644
--- a/coders/farbfeld.c
+++ b/coders/farbfeld.c
@@ -184,8 +184,6 @@ static Image *ReadFARBFELDImage(const ImageInfo *image_info,
image->alpha_trait=BlendPixelTrait;
if (image_info->ping != MagickFalse)
{
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
diff --git a/coders/hdr.c b/coders/hdr.c
index c78da3797..3d3c355ba 100644
--- a/coders/hdr.c
+++ b/coders/hdr.c
@@ -361,8 +361,6 @@ static Image *ReadHDRImage(const ImageInfo *image_info,ExceptionInfo *exception)
while (isspace((int) ((unsigned char) c)) != 0)
c=ReadBlobByte(image);
}
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize");
if (LocaleCompare(format,"32-bit_rle_rgbe") == 0)
(void) SetImageColorspace(image,RGBColorspace,exception);
else if (LocaleCompare(format,"32-bit_rle_xyze") == 0)
diff --git a/coders/mtv.c b/coders/mtv.c
index f9f9d1d6e..ea03a69ad 100644
--- a/coders/mtv.c
+++ b/coders/mtv.c
@@ -159,11 +159,7 @@ static Image *ReadMTVImage(const ImageInfo *image_info,ExceptionInfo *exception)
image->depth=8;
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
- {
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
- break;
- }
+ break;
status=SetImageExtent(image,image->columns,image->rows,exception);
if (status == MagickFalse)
return(DestroyImageList(image));
diff --git a/coders/otb.c b/coders/otb.c
index 0931722f4..174c80d88 100644
--- a/coders/otb.c
+++ b/coders/otb.c
@@ -153,8 +153,6 @@ static Image *ReadOTBImage(const ImageInfo *image_info,ExceptionInfo *exception)
image->columns=(size_t) ReadBlobMSBShort(image);
image->rows=(size_t) ReadBlobMSBShort(image);
}
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
depth=(unsigned char) ReadBlobByte(image);
if (depth != 1)
ThrowReaderException(CoderError,"OnlyLevelZerofilesSupported");
diff --git a/coders/palm.c b/coders/palm.c
index 028d7f3be..fd626b095 100644
--- a/coders/palm.c
+++ b/coders/palm.c
@@ -310,8 +310,6 @@ static Image *ReadPALMImage(const ImageInfo *image_info,
image->rows=ReadBlobMSBShort(image);
if (EOFBlob(image) != MagickFalse)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize");
status=SetImageExtent(image,image->columns,image->rows,exception);
if (status == MagickFalse)
return(DestroyImageList(image));
diff --git a/coders/pdb.c b/coders/pdb.c
index 0f53b9da2..00d4e2f0f 100644
--- a/coders/pdb.c
+++ b/coders/pdb.c
@@ -405,8 +405,6 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if (image_info->ping != MagickFalse)
{
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
diff --git a/coders/pgx.c b/coders/pgx.c
index 1bdf49c5d..1221ed542 100644
--- a/coders/pgx.c
+++ b/coders/pgx.c
@@ -190,8 +190,6 @@ static Image *ReadPGXImage(const ImageInfo *image_info,ExceptionInfo *exception)
image->endian=MSBEndian;
image->columns=(size_t) width;
image->rows=(size_t) height;
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
diff --git a/coders/pict.c b/coders/pict.c
index 2b516a679..0e60638b1 100644
--- a/coders/pict.c
+++ b/coders/pict.c
@@ -958,8 +958,6 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
{
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
diff --git a/coders/pnm.c b/coders/pnm.c
index ae57cdb3a..8481f5964 100644
--- a/coders/pnm.c
+++ b/coders/pnm.c
@@ -493,8 +493,6 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
}
if (quantum_type == UndefinedQuantum)
quantum_type=RGBQuantum;
- if ((image->columns == 0) || (image->rows == 0))
- ThrowPNMException(CorruptImageError,"NegativeOrZeroImageSize");
if ((max_value == 0) || (max_value > 4294967295UL))
ThrowPNMException(CorruptImageError,"ImproperImageHeader");
for (depth=1; GetQuantumRange(depth) < max_value; depth++) ;
diff --git a/coders/rgf.c b/coders/rgf.c
index 41a70d8da..39df4b874 100644
--- a/coders/rgf.c
+++ b/coders/rgf.c
@@ -167,8 +167,6 @@ static Image *ReadRGFImage(const ImageInfo *image_info,ExceptionInfo *exception)
image->colormap[1].blue=(Quantum) 0;
if (image_info->ping != MagickFalse)
{
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
diff --git a/coders/rla.c b/coders/rla.c
index 991dbd312..6d7d5e21b 100644
--- a/coders/rla.c
+++ b/coders/rla.c
@@ -268,8 +268,6 @@ static Image *ReadRLAImage(const ImageInfo *image_info,ExceptionInfo *exception)
rla_info.active_window.bottom+1);
if (image_info->ping != MagickFalse)
{
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
diff --git a/coders/sgi.c b/coders/sgi.c
index 608f72508..d9d1e5871 100644
--- a/coders/sgi.c
+++ b/coders/sgi.c
@@ -373,11 +373,7 @@ static Image *ReadSGIImage(const ImageInfo *image_info,ExceptionInfo *exception)
}
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
- {
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
- break;
- }
+ break;
if ((MagickSizeType) (image->columns*image->rows/255) > GetBlobSize(image))
ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
status=SetImageExtent(image,image->columns,image->rows,exception);
diff --git a/coders/tga.c b/coders/tga.c
index 24eff3d16..36406ec1c 100644
--- a/coders/tga.c
+++ b/coders/tga.c
@@ -344,8 +344,6 @@ static Image *ReadTGAImage(const ImageInfo *image_info,ExceptionInfo *exception)
image->orientation=TopLeftOrientation;
if (image_info->ping != MagickFalse)
{
- if ((image->columns == 0) || (image->rows == 0))
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(void) CloseBlob(image);
return(image);
}