From: Cristy Date: Fri, 16 Sep 2016 00:24:46 +0000 (-0400) Subject: https://github.com/ImageMagick/ImageMagick/issues/268 X-Git-Tag: 7.0.3-1~29 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6e48aa92ff4e6e95424300ecd52a9ea453c19c60;p=imagemagick https://github.com/ImageMagick/ImageMagick/issues/268 --- diff --git a/coders/tiff.c b/coders/tiff.c index 74584c5f2..daab01eba 100644 --- a/coders/tiff.c +++ b/coders/tiff.c @@ -1425,69 +1425,7 @@ RestoreMSCWarning case COMPRESSION_ADOBE_DEFLATE: image->compression=ZipCompression; break; default: image->compression=RLECompression; break; } - /* - Allocate memory for the image and pixel buffer. - */ - quantum_info=AcquireQuantumInfo(image_info,image); - if (quantum_info == (QuantumInfo *) NULL) - { - TIFFClose(tiff); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - } - if (sample_format == SAMPLEFORMAT_UINT) - status=SetQuantumFormat(image,quantum_info,UnsignedQuantumFormat); - if (sample_format == SAMPLEFORMAT_INT) - status=SetQuantumFormat(image,quantum_info,SignedQuantumFormat); - if (sample_format == SAMPLEFORMAT_IEEEFP) - status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat); - if (status == MagickFalse) - { - TIFFClose(tiff); - quantum_info=DestroyQuantumInfo(quantum_info); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - } - status=MagickTrue; - switch (photometric) - { - case PHOTOMETRIC_MINISBLACK: - { - quantum_info->min_is_white=MagickFalse; - break; - } - case PHOTOMETRIC_MINISWHITE: - { - quantum_info->min_is_white=MagickTrue; - break; - } - default: - break; - } - tiff_status=TIFFGetFieldDefaulted(tiff,TIFFTAG_EXTRASAMPLES,&extra_samples, - &sample_info); - if (tiff_status == 1) - { - (void) SetImageProperty(image,"tiff:alpha","unspecified",exception); - if (extra_samples == 0) - { - if ((samples_per_pixel == 4) && (photometric == PHOTOMETRIC_RGB)) - image->alpha_trait=BlendPixelTrait; - } - else - for (i=0; i < extra_samples; i++) - { - image->alpha_trait=BlendPixelTrait; - if (sample_info[i] == EXTRASAMPLE_ASSOCALPHA) - { - SetQuantumAlphaType(quantum_info,DisassociatedQuantumAlpha); - (void) SetImageProperty(image,"tiff:alpha","associated", - exception); - } - else - if (sample_info[i] == EXTRASAMPLE_UNASSALPHA) - (void) SetImageProperty(image,"tiff:alpha","unassociated", - exception); - } - } + quantum_info=(QuantumInfo *) NULL; if ((photometric == PHOTOMETRIC_PALETTE) && (pow(2.0,1.0*bits_per_sample) <= MaxColormapSize)) { @@ -1554,15 +1492,75 @@ RestoreMSCWarning { if (image_info->number_scenes != 0) if (image->scene >= (image_info->scene+image_info->number_scenes-1)) - { - quantum_info=DestroyQuantumInfo(quantum_info); - break; - } + break; goto next_tiff_frame; } status=SetImageExtent(image,image->columns,image->rows,exception); if (status == MagickFalse) return(DestroyImageList(image)); + /* + Allocate memory for the image and pixel buffer. + */ + quantum_info=AcquireQuantumInfo(image_info,image); + if (quantum_info == (QuantumInfo *) NULL) + { + TIFFClose(tiff); + ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); + } + if (sample_format == SAMPLEFORMAT_UINT) + status=SetQuantumFormat(image,quantum_info,UnsignedQuantumFormat); + if (sample_format == SAMPLEFORMAT_INT) + status=SetQuantumFormat(image,quantum_info,SignedQuantumFormat); + if (sample_format == SAMPLEFORMAT_IEEEFP) + status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat); + if (status == MagickFalse) + { + TIFFClose(tiff); + quantum_info=DestroyQuantumInfo(quantum_info); + ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); + } + status=MagickTrue; + switch (photometric) + { + case PHOTOMETRIC_MINISBLACK: + { + quantum_info->min_is_white=MagickFalse; + break; + } + case PHOTOMETRIC_MINISWHITE: + { + quantum_info->min_is_white=MagickTrue; + break; + } + default: + break; + } + tiff_status=TIFFGetFieldDefaulted(tiff,TIFFTAG_EXTRASAMPLES,&extra_samples, + &sample_info); + if (tiff_status == 1) + { + (void) SetImageProperty(image,"tiff:alpha","unspecified",exception); + if (extra_samples == 0) + { + if ((samples_per_pixel == 4) && (photometric == PHOTOMETRIC_RGB)) + image->alpha_trait=BlendPixelTrait; + } + else + for (i=0; i < extra_samples; i++) + { + image->alpha_trait=BlendPixelTrait; + if (sample_info[i] == EXTRASAMPLE_ASSOCALPHA) + { + SetQuantumAlphaType(quantum_info,DisassociatedQuantumAlpha); + (void) SetImageProperty(image,"tiff:alpha","associated", + exception); + } + else + if (sample_info[i] == EXTRASAMPLE_UNASSALPHA) + (void) SetImageProperty(image,"tiff:alpha","unassociated", + exception); + } + } method=ReadGenericMethod; if (TIFFGetField(tiff,TIFFTAG_ROWSPERSTRIP,&rows_per_strip) == 1) { @@ -2072,7 +2070,8 @@ RestoreMSCWarning } SetQuantumImageType(image,quantum_type); next_tiff_frame: - quantum_info=DestroyQuantumInfo(quantum_info); + if (quantum_info != (QuantumInfo *) NULL) + quantum_info=DestroyQuantumInfo(quantum_info); if (photometric == PHOTOMETRIC_CIELAB) DecodeLabImage(image,exception); if ((photometric == PHOTOMETRIC_LOGL) ||