Commit 0bf98afe7 for imagemagick.org
commit 0bf98afe7ff67f6b2e243d30f52141989067009c
Author: Cristy <urban-warrior@imagemagick.org>
Date: Wed Dec 2 17:55:32 2026 -0500
use DestroyImageList() to destroy the all the image frames rather than just the first
diff --git a/coders/thumbnail.c b/coders/thumbnail.c
index c53184cb2..b75c01922 100644
--- a/coders/thumbnail.c
+++ b/coders/thumbnail.c
@@ -46,6 +46,7 @@
#include "MagickCore/constitute.h"
#include "MagickCore/exception.h"
#include "MagickCore/exception-private.h"
+#include "MagickCore/list.h"
#include "MagickCore/magick.h"
#include "MagickCore/memory_.h"
#include "MagickCore/module.h"
@@ -171,18 +172,26 @@ static MagickBooleanType WriteTHUMBNAILImage(const ImageInfo *image_info,
MagickBooleanType
status;
- ssize_t
- i;
-
size_t
- length;
+ length,
+ offset,
+ profile_length;
ssize_t
- offset;
+ value;
unsigned char
+ *datum,
+ *end,
*q;
+ assert(image_info != (const ImageInfo *) NULL);
+ assert(image_info->signature == MagickCoreSignature);
+ assert(image != (Image *) NULL);
+ assert(image->signature == MagickCoreSignature);
+ assert(exception != (ExceptionInfo *) NULL);
+ if (IsEventLogging() != MagickFalse)
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
profile=GetImageProfile(image,"exif");
if (profile == (const StringInfo *) NULL)
ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
@@ -190,23 +199,36 @@ static MagickBooleanType WriteTHUMBNAILImage(const ImageInfo *image_info,
exception);
if (property == (const char *) NULL)
ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
- offset=(ssize_t) StringToLong(property);
- if (offset < 0)
+ value=(ssize_t) StringToLong(property);
+ if (value < 0)
ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
+ offset=(size_t) value;
property=GetImageProperty(image,"exif:Thumbnail.JPEGInterchangeFormatLength",
exception);
if (property == (const char *) NULL)
ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
- length=(size_t) StringToLong(property);
- q=GetStringInfoDatum(profile)+offset;
- for (i=offset; i < (ssize_t) GetStringInfoLength(profile) - 3; i++)
- {
+ value=(ssize_t) StringToLong(property);
+ if (value <= 0)
+ ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
+ length=(size_t) value;
+ /*
+ Validate the untrusted EXIF offset/length against the profile before doing
+ any pointer arithmetic. The offset is relative to the TIFF header, which
+ sits behind the "Exif\0\0" prefix in the profile, so scan forward from the
+ offset for the JPEG SOI marker (FF D8 FF).
+ */
+ datum=GetStringInfoDatum(profile);
+ profile_length=GetStringInfoLength(profile);
+ if ((datum == (unsigned char *) NULL) || (profile_length < 3) ||
+ (offset > (profile_length-3)))
+ ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
+ end=datum+profile_length;
+ for (q=datum+offset; q <= (end-3); q++)
if (memcmp(q,"\377\330\377",3) == 0)
break;
- q++;
- }
- if ((q > (GetStringInfoDatum(profile)+GetStringInfoLength(profile))) ||
- (length > (size_t) (GetStringInfoDatum(profile)+GetStringInfoLength(profile)-q)))
+ if (q > (end-3))
+ ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
+ if (length > (size_t) (end-q))
ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
write_info=CloneImageInfo(image_info);
*write_info->magick='\0';
@@ -216,8 +238,14 @@ static MagickBooleanType WriteTHUMBNAILImage(const ImageInfo *image_info,
write_info=DestroyImageInfo(write_info);
return(MagickFalse);
}
- (void) SetImageType(thumbnail_image,thumbnail_image->alpha_trait ==
+ status=SetImageType(thumbnail_image,thumbnail_image->alpha_trait ==
UndefinedPixelTrait ? TrueColorType : TrueColorAlphaType,exception);
+ if (status == MagickFalse)
+ {
+ thumbnail_image=DestroyImageList(thumbnail_image);
+ write_info=DestroyImageInfo(write_info);
+ return(MagickFalse);
+ }
(void) CopyMagickString(thumbnail_image->filename,image->filename,
MagickPathExtent);
*write_info->magick='\0';
@@ -228,7 +256,7 @@ static MagickBooleanType WriteTHUMBNAILImage(const ImageInfo *image_info,
(void) FormatLocaleString(thumbnail_image->filename,MagickPathExtent,
"miff:%s",write_info->filename);
status=WriteImage(write_info,thumbnail_image,exception);
- thumbnail_image=DestroyImage(thumbnail_image);
+ thumbnail_image=DestroyImageList(thumbnail_image);
write_info=DestroyImageInfo(write_info);
return(status);
}