From: Cristy Date: Thu, 7 Sep 2017 11:18:41 +0000 (-0400) Subject: https://github.com/ImageMagick/ImageMagick/issues/736 X-Git-Tag: 7.0.7-1~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=32a3eeb9e0da083cbc05909e4935efdbf9846df9;p=imagemagick https://github.com/ImageMagick/ImageMagick/issues/736 --- diff --git a/coders/tiff.c b/coders/tiff.c index ca34bc684..2376e8b2b 100644 --- a/coders/tiff.c +++ b/coders/tiff.c @@ -1211,6 +1211,16 @@ static void TIFFReadPhotoshopLayers(Image* image,const ImageInfo *image_info, static Image *ReadTIFFImage(const ImageInfo *image_info, ExceptionInfo *exception) { +#define ThrowTIFFException(severity,message) \ +{ \ + if (tiff_pixels != (unsigned char *) NULL) \ + tiff_pixels=(unsigned char *) RelinquishMagickMemory(tiff_pixels); \ + if (quantum_info != (QuantumInfo *) NULL) \ + quantum_info=DestroyQuantumInfo(quantum_info); \ + TIFFClose(tiff); \ + ThrowReaderException(severity,message); \ +} + const char *option; @@ -1639,12 +1649,10 @@ RestoreMSCWarning /* Allocate memory for the image and pixel buffer. */ + tiff_pixels=(unsigned char *) NULL; quantum_info=AcquireQuantumInfo(image_info,image); if (quantum_info == (QuantumInfo *) NULL) - { - TIFFClose(tiff); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - } + ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed"); if (sample_format == SAMPLEFORMAT_UINT) status=SetQuantumFormat(image,quantum_info,UnsignedQuantumFormat); if (sample_format == SAMPLEFORMAT_INT) @@ -1652,11 +1660,7 @@ RestoreMSCWarning if (sample_format == SAMPLEFORMAT_IEEEFP) status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat); if (status == MagickFalse) - { - TIFFClose(tiff); - quantum_info=DestroyQuantumInfo(quantum_info); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - } + ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed"); status=MagickTrue; switch (photometric) { @@ -1743,10 +1747,7 @@ RestoreMSCWarning TIFFScanlineSize(tiff),(ssize_t) (image->columns*samples_per_pixel* pow(2.0,ceil(log(bits_per_sample)/log(2.0)))))); if (tiff_pixels == (unsigned char *) NULL) - { - TIFFClose(tiff); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - } + ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed"); switch (method) { case ReadSingleSampleMethod: @@ -1779,10 +1780,7 @@ RestoreMSCWarning status=SetQuantumPad(image,quantum_info,pad*pow(2,ceil(log( bits_per_sample)/log(2)))); if (status == MagickFalse) - { - TIFFClose(tiff); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - } + ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed"); for (y=0; y < (ssize_t) image->rows; y++) { int @@ -1835,10 +1833,7 @@ RestoreMSCWarning } status=SetQuantumPad(image,quantum_info,pad*((bits_per_sample+7) >> 3)); if (status == MagickFalse) - { - TIFFClose(tiff); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - } + ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed"); for (y=0; y < (ssize_t) image->rows; y++) { int @@ -2042,24 +2037,18 @@ RestoreMSCWarning */ if ((TIFFGetField(tiff,TIFFTAG_TILEWIDTH,&columns) != 1) || (TIFFGetField(tiff,TIFFTAG_TILELENGTH,&rows) != 1)) - { - TIFFClose(tiff); - ThrowReaderException(CoderError,"ImageIsNotTiled"); - } + ThrowTIFFException(CoderError,"ImageIsNotTiled"); + if ((AcquireMagickResource(WidthResource,columns) == MagickFalse) || + (AcquireMagickResource(HeightResource,rows) == MagickFalse)) + ThrowTIFFException(ImageError,"WidthOrHeightExceedsLimit"); (void) SetImageStorageClass(image,DirectClass,exception); number_pixels=(MagickSizeType) columns*rows; if (HeapOverflowSanityCheck(rows,sizeof(*tile_pixels)) != MagickFalse) - { - TIFFClose(tiff); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - } + ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed"); tile_pixels=(uint32 *) AcquireQuantumMemory(columns,rows* sizeof(*tile_pixels)); if (tile_pixels == (uint32 *) NULL) - { - TIFFClose(tiff); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - } + ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed"); for (y=0; y < (ssize_t) image->rows; y+=rows) { register ssize_t @@ -2156,17 +2145,11 @@ RestoreMSCWarning */ number_pixels=(MagickSizeType) image->columns*image->rows; if (HeapOverflowSanityCheck(image->rows,sizeof(*pixels)) != MagickFalse) - { - TIFFClose(tiff); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - } + ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed"); pixel_info=AcquireVirtualMemory(image->columns,image->rows* sizeof(uint32)); if (pixel_info == (MemoryInfo *) NULL) - { - TIFFClose(tiff); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - } + ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed"); pixels=(uint32 *) GetVirtualMemoryBlob(pixel_info); (void) TIFFReadRGBAImage(tiff,(uint32) image->columns,(uint32) image->rows,(uint32 *) pixels,0); @@ -3114,9 +3097,6 @@ static MagickBooleanType TIFFWritePhotoshopLayers(Image* image, PSDInfo info; - size_t - length; - StringInfo *layers; @@ -3125,8 +3105,8 @@ static MagickBooleanType TIFFWritePhotoshopLayers(Image* image, return(MagickTrue); clone_info=CloneImageInfo(image_info); if (clone_info == (ImageInfo *) NULL) - ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", - image->filename); + ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", + image->filename); profile.offset=0; profile.quantum=MagickMinBlobExtent; layers=AcquireStringInfo(profile.quantum);