diff --git a/coders/tiff.c b/coders/tiff.c index b778aa18ef5..c6a56f3bcb6 100644 --- a/coders/tiff.c +++ b/coders/tiff.c @@ -1360,6 +1360,11 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, TIFFClose(tiff); ThrowReaderException(CorruptImageError,"UnsupportedBitsPerPixel"); } + if (samples_per_pixel > MaxPixelChannels) + { + TIFFClose(tiff); + ThrowReaderException(CorruptImageError,"MaximumChannelsExceeded"); + } if (sample_format == SAMPLEFORMAT_IEEEFP) (void) SetImageProperty(image,"quantum:format","floating-point", exception); @@ -1728,11 +1733,6 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, } if (image->alpha_trait != UndefinedPixelTrait) (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception); - if (samples_per_pixel > MaxPixelChannels) - { - TIFFClose(tiff); - ThrowReaderException(CorruptImageError,"MaximumChannelsExceeded"); - } method=ReadGenericMethod; rows_per_strip=(uint32) image->rows; if (TIFFGetField(tiff,TIFFTAG_ROWSPERSTRIP,&rows_per_strip) == 1)