Commit 3d0146c2e for imagemagick.org
commit 3d0146c2e9b5eb5e97b2cad43d392a49ea64c338
Author: Cristy <urban-warrior@imagemagick.org>
Date: Wed Dec 2 20:01:42 2026 -0500
add a recursion guard
diff --git a/coders/tile.c b/coders/tile.c
index 3dd6165e0..6f8604a60 100644
--- a/coders/tile.c
+++ b/coders/tile.c
@@ -108,10 +108,19 @@ static Image *ReadTILEImage(const ImageInfo *image_info,
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
image=AcquireImage(image_info,exception);
+ if (image == (Image *) NULL)
+ return((Image *) NULL);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
if (*image_info->filename == '\0')
ThrowReaderException(OptionError,"MustSpecifyAnImageName");
+ /*
+ Refuse self-referential specs such as tile:tile:tile:... -- each level
+ would recurse into this reader and allocate another image, so a long
+ filename could exhaust the stack and memory.
+ */
+ if (LocaleNCompare(image_info->filename,"tile:",5) == 0)
+ ThrowReaderException(OptionError,"NestedTileImagesAreNotPermitted");
status=SetImageExtent(image,image->columns,image->rows,exception);
if (status == MagickFalse)
return(DestroyImageList(image));
@@ -124,6 +133,7 @@ static Image *ReadTILEImage(const ImageInfo *image_info,
read_info=DestroyImageInfo(read_info);
if (tile_image == (Image *) NULL)
return(DestroyImageList(image));
+ tile_image=GetFirstImageInList(tile_image);
image->colorspace=tile_image->colorspace;
image->alpha_trait=tile_image->alpha_trait;
(void) CopyMagickString(image->filename,image_info->filename,
@@ -133,8 +143,14 @@ static Image *ReadTILEImage(const ImageInfo *image_info,
tile_image->tile_offset.x=0;
tile_image->tile_offset.y=0;
}
- (void) TextureImage(image,tile_image,exception);
- tile_image=DestroyImage(tile_image);
+ status=TextureImage(image,tile_image,exception);
+ /*
+ The texture may have been a multi-frame image; free every frame, not just
+ the first one.
+ */
+ tile_image=DestroyImageList(tile_image);
+ if (status == MagickFalse)
+ return(DestroyImageList(image));
if ((image->colorspace == LinearGRAYColorspace) ||
(image->colorspace == GRAYColorspace))
image->type=GrayscaleType;