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;
/*
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)
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)
{
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:
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
}
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
*/
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
*/
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);
PSDInfo
info;
- size_t
- length;
-
StringInfo
*layers;
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);