Commit 766412f38 for imagemagick.org
commit 766412f38f8b0a68ecf581e3219bc093372cbedc
Author: Cristy <urban-warrior@imagemagick.org>
Date: Fri Dec 4 18:44:57 2026 -0500
ReadMTVImage now rejects headers whose width*height*3 is larger than the file
diff --git a/coders/mtv.c b/coders/mtv.c
index 886324b22..c3295fd17 100644
--- a/coders/mtv.c
+++ b/coders/mtv.c
@@ -160,6 +160,15 @@ static Image *ReadMTVImage(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))
break;
+ if ((image->columns == 0) || (image->rows == 0))
+ ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize");
+ /*
+ Each pixel needs 3 bytes; refuse headers that claim more pixels than the
+ file can hold before allocating the pixel cache.
+ */
+ if (((MagickSizeType) image->columns*image->rows) >
+ (GetBlobSize(image)/3))
+ ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
status=SetImageExtent(image,image->columns,image->rows,exception);
if (status == MagickFalse)
return(DestroyImageList(image));
@@ -181,7 +190,10 @@ static Image *ReadMTVImage(const ImageInfo *image_info,ExceptionInfo *exception)
p=pixels;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
- break;
+ {
+ status=MagickFalse;
+ break;
+ }
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(image,ScaleCharToQuantum(*p++),q);
@@ -191,7 +203,10 @@ static Image *ReadMTVImage(const ImageInfo *image_info,ExceptionInfo *exception)
q+=(ptrdiff_t) GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
- break;
+ {
+ status=MagickFalse;
+ break;
+ }
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
@@ -201,6 +216,8 @@ static Image *ReadMTVImage(const ImageInfo *image_info,ExceptionInfo *exception)
}
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ if (status == MagickFalse)
+ break;
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",