summaryrefslogtreecommitdiff
path: root/coders/tiff.c
diff options
context:
space:
mode:
Diffstat (limited to 'coders/tiff.c')
-rw-r--r--coders/tiff.c163
1 files changed, 89 insertions, 74 deletions
diff --git a/coders/tiff.c b/coders/tiff.c
index 1eecf17ae..92d30724a 100644
--- a/coders/tiff.c
+++ b/coders/tiff.c
@@ -17,7 +17,7 @@
% July 1992 %
% %
% %
-% Copyright 1999-2020 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2021 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
@@ -254,8 +254,8 @@ static MagickOffsetType TIFFSeekCustomStream(const MagickOffsetType offset,
}
case SEEK_CUR:
{
- if (((offset > 0) && (profile->offset > (SSIZE_MAX-offset))) ||
- ((offset < 0) && (profile->offset < (-SSIZE_MAX-offset))))
+ if (((offset > 0) && (profile->offset > (LONG_MAX-offset))) ||
+ ((offset < 0) && (profile->offset < (LONG_MIN-offset))))
{
errno=EOVERFLOW;
return(-1);
@@ -567,10 +567,10 @@ static MagickBooleanType DecodeLabImage(Image *image,ExceptionInfo *exception)
image_view=AcquireAuthenticCacheView(image,exception);
for (y=0; y < (ssize_t) image->rows; y++)
{
- register Quantum
+ Quantum
*magick_restrict q;
- register ssize_t
+ ssize_t
x;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
@@ -838,7 +838,7 @@ static void TIFFGetEXIFProperties(TIFF *tiff,Image *image,
char
value[MagickPathExtent];
- register ssize_t
+ ssize_t
i;
tdir_t
@@ -852,7 +852,7 @@ static void TIFFGetEXIFProperties(TIFF *tiff,Image *image,
offset;
void
- *sans[2] = { NULL, NULL };
+ *sans[4] = { NULL, NULL, NULL, NULL };
/*
Read EXIF properties.
@@ -1066,7 +1066,7 @@ static TIFFMethodType GetJPEGMethod(Image* image,TIFF *tiff,uint16 photometric,
position,
offset;
- register size_t
+ size_t
i;
TIFFMethodType
@@ -1202,7 +1202,7 @@ static void TIFFReadPhotoshopLayers(const ImageInfo *image_info,Image *image,
PSDInfo
info;
- register ssize_t
+ ssize_t
i;
if (GetImageListLength(image) != 1)
@@ -1302,12 +1302,14 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
tiff_status;
MagickBooleanType
- more_frames,
- status;
+ more_frames;
MagickSizeType
number_pixels;
+ MagickStatusType
+ status;
+
MemoryInfo
*pixel_info = (MemoryInfo *) NULL;
@@ -1317,12 +1319,9 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
QuantumType
quantum_type;
- register ssize_t
+ ssize_t
i;
- size_t
- pad;
-
ssize_t
y;
@@ -1590,8 +1589,10 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
if ((TIFFGetFieldDefaulted(tiff,TIFFTAG_XPOSITION,&x_position,sans) == 1) &&
(TIFFGetFieldDefaulted(tiff,TIFFTAG_YPOSITION,&y_position,sans) == 1))
{
- image->page.x=(ssize_t) ceil(x_position*image->resolution.x-0.5);
- image->page.y=(ssize_t) ceil(y_position*image->resolution.y-0.5);
+ image->page.x=CastDoubleToLong(ceil(x_position*
+ image->resolution.x-0.5));
+ image->page.y=CastDoubleToLong(ceil(y_position*
+ image->resolution.y-0.5));
}
if (TIFFGetFieldDefaulted(tiff,TIFFTAG_ORIENTATION,&orientation,sans) == 1)
image->orientation=(OrientationType) orientation;
@@ -1843,13 +1844,12 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
ThrowTIFFException(ImageError,"WidthOrHeightExceedsLimit");
method=ReadTileMethod;
}
+ if (photometric == PHOTOMETRIC_LOGLUV)
+ method=ReadGenericMethod;
if (image->compression == JPEGCompression)
method=GetJPEGMethod(image,tiff,photometric,bits_per_sample,
samples_per_pixel);
- if (photometric == PHOTOMETRIC_LOGLUV)
- method=ReadGenericMethod;
quantum_info->endian=LSBEndian;
- quantum_type=RGBQuantum;
if (TIFFScanlineSize(tiff) <= 0)
ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
if ((1.0*TIFFScanlineSize(tiff)) > (2.53*GetBlobSize(image)))
@@ -1862,40 +1862,47 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
pixels=(unsigned char *) GetVirtualMemoryBlob(pixel_info);
(void) memset(pixels,0,number_pixels*sizeof(uint32));
- quantum_type=IndexQuantum;
- pad=(size_t) MagickMax((ssize_t) samples_per_pixel-1,0);
- if (image->alpha_trait != UndefinedPixelTrait)
- {
- if (image->storage_class == PseudoClass)
- quantum_type=IndexAlphaQuantum;
- else
- quantum_type=samples_per_pixel == 1 ? AlphaQuantum : GrayAlphaQuantum;
- }
- else
- if (image->storage_class != PseudoClass)
- quantum_type=GrayQuantum;
- if ((samples_per_pixel > 2) && (interlace != PLANARCONFIG_SEPARATE))
+ quantum_type=GrayQuantum;
+ if (image->storage_class == PseudoClass)
+ quantum_type=IndexQuantum;
+ if (interlace != PLANARCONFIG_SEPARATE)
{
- pad=(size_t) MagickMax((size_t) samples_per_pixel-3,0);
- quantum_type=RGBQuantum;
+ size_t
+ pad;
+
+ pad=(size_t) MagickMax((ssize_t) samples_per_pixel-1,0);
if (image->alpha_trait != UndefinedPixelTrait)
{
- quantum_type=RGBAQuantum;
- pad=(size_t) MagickMax((size_t) samples_per_pixel-4,0);
+ if (image->storage_class == PseudoClass)
+ quantum_type=IndexAlphaQuantum;
+ else
+ quantum_type=samples_per_pixel == 1 ? AlphaQuantum :
+ GrayAlphaQuantum;
}
- if (image->colorspace == CMYKColorspace)
+ if ((samples_per_pixel > 2) && (interlace != PLANARCONFIG_SEPARATE))
{
- pad=(size_t) MagickMax((size_t) samples_per_pixel-4,0);
- quantum_type=CMYKQuantum;
+ quantum_type=RGBQuantum;
+ pad=(size_t) MagickMax((size_t) samples_per_pixel-3,0);
if (image->alpha_trait != UndefinedPixelTrait)
{
- quantum_type=CMYKAQuantum;
- pad=(size_t) MagickMax((size_t) samples_per_pixel-5,0);
+ quantum_type=RGBAQuantum;
+ pad=(size_t) MagickMax((size_t) samples_per_pixel-4,0);
}
+ if (image->colorspace == CMYKColorspace)
+ {
+ quantum_type=CMYKQuantum;
+ pad=(size_t) MagickMax((size_t) samples_per_pixel-4,0);
+ if (image->alpha_trait != UndefinedPixelTrait)
+ {
+ quantum_type=CMYKAQuantum;
+ pad=(size_t) MagickMax((size_t) samples_per_pixel-5,0);
+ }
+ }
+ status=SetQuantumPad(image,quantum_info,pad*((bits_per_sample+7) >>
+ 3));
+ if (status == MagickFalse)
+ ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
}
- status=SetQuantumPad(image,quantum_info,pad*((bits_per_sample+7) >> 3));
- if (status == MagickFalse)
- ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
}
switch (method)
{
@@ -1906,10 +1913,10 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
- register Quantum
+ Quantum
*magick_restrict q;
- register ssize_t
+ ssize_t
x;
unsigned char
@@ -1949,7 +1956,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
}
case ReadStripMethod:
{
- register unsigned char
+ unsigned char
*p;
size_t
@@ -1968,14 +1975,14 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
/*
Convert stripped TIFF image.
*/
- extent=TIFFStripSize(tiff);
+ extent=2*TIFFStripSize(tiff);
#if defined(TIFF_VERSION_BIG)
extent+=image->columns*sizeof(uint64);
#else
extent+=image->columns*sizeof(uint32);
#endif
strip_pixels=(unsigned char *) AcquireQuantumMemory(extent,
- 2*sizeof(*strip_pixels));
+ sizeof(*strip_pixels));
if (strip_pixels == (unsigned char *) NULL)
ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
(void) memset(strip_pixels,0,extent*sizeof(*strip_pixels));
@@ -1994,16 +2001,18 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
case 2: quantum_type=BlueQuantum; break;
case 3:
{
+ quantum_type=AlphaQuantum;
if (image->colorspace == CMYKColorspace)
quantum_type=BlackQuantum;
break;
}
case 4: quantum_type=AlphaQuantum; break;
+ default: break;
}
rows_remaining=0;
for (y=0; y < (ssize_t) image->rows; y++)
{
- register Quantum
+ Quantum
*magick_restrict q;
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
@@ -2016,7 +2025,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
if (strip_size == -1)
break;
rows_remaining=rows_per_strip;
- if ((y+rows_per_strip) > image->rows)
+ if ((y+rows_per_strip) > (ssize_t) image->rows)
rows_remaining=(rows_per_strip-(y+rows_per_strip-
image->rows));
p=strip_pixels;
@@ -2044,7 +2053,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
}
case ReadTileMethod:
{
- register unsigned char
+ unsigned char
*p;
size_t
@@ -2086,15 +2095,17 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
case 2: quantum_type=BlueQuantum; break;
case 3:
{
+ quantum_type=AlphaQuantum;
if (image->colorspace == CMYKColorspace)
quantum_type=BlackQuantum;
break;
}
case 4: quantum_type=AlphaQuantum; break;
+ default: break;
}
for (y=0; y < (ssize_t) image->rows; y+=rows)
{
- register ssize_t
+ ssize_t
x;
size_t
@@ -2117,7 +2128,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
p=tile_pixels;
for (row=0; row < rows_remaining; row++)
{
- register Quantum
+ Quantum
*magick_restrict q;
q=GetAuthenticPixels(image,x,y+row,columns_remaining,1,
@@ -2151,7 +2162,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
MemoryInfo
*generic_info = (MemoryInfo * ) NULL;
- register uint32
+ uint32
*p;
uint32
@@ -2163,7 +2174,11 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
if (HeapOverflowSanityCheck(image->rows,sizeof(*pixels)) != MagickFalse)
ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
number_pixels=(MagickSizeType) image->columns*image->rows;
+#if defined(TIFF_VERSION_BIG)
+ number_pixels+=image->columns*sizeof(uint64);
+#else
number_pixels+=image->columns*sizeof(uint32);
+#endif
generic_info=AcquireVirtualMemory(number_pixels,sizeof(uint32));
if (generic_info == (MemoryInfo *) NULL)
ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
@@ -2173,10 +2188,10 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
p=pixels+(image->columns*image->rows)-1;
for (y=0; y < (ssize_t) image->rows; y++)
{
- register ssize_t
+ ssize_t
x;
- register Quantum
+ Quantum
*magick_restrict q;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
@@ -2304,7 +2319,7 @@ static void TIFFIgnoreTags(TIFF *tiff)
Image
*image;
- register ssize_t
+ ssize_t
i;
size_t
@@ -2421,7 +2436,7 @@ ModuleExport size_t RegisterTIFFImage(void)
const char
*p;
- register ssize_t
+ ssize_t
i;
p=TIFFGetVersion();
@@ -2595,7 +2610,7 @@ static MagickBooleanType WriteGROUP4Image(const ImageInfo *image_info,
MagickBooleanType
status;
- register ssize_t
+ ssize_t
i;
ssize_t
@@ -2889,10 +2904,10 @@ static MagickBooleanType EncodeLabImage(Image *image,ExceptionInfo *exception)
image_view=AcquireAuthenticCacheView(image,exception);
for (y=0; y < (ssize_t) image->rows; y++)
{
- register Quantum
+ Quantum
*magick_restrict q;
- register ssize_t
+ ssize_t
x;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
@@ -3004,10 +3019,10 @@ static int32 TIFFWritePixels(TIFF *tiff,TIFFInfo *tiff_info,ssize_t row,
int32
status;
- register ssize_t
+ ssize_t
i;
- register unsigned char
+ unsigned char
*p,
*q;
@@ -3344,7 +3359,7 @@ static void TIFFSetEXIFProperties(TIFF *tiff,Image *image,
const char
*value;
- register ssize_t
+ ssize_t
i;
uint32
@@ -3434,7 +3449,7 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,
QuantumType
quantum_type;
- register ssize_t
+ ssize_t
i;
size_t
@@ -4087,7 +4102,7 @@ RestoreMSCWarning
quantum_type=RGBAQuantum;
for (y=0; y < (ssize_t) image->rows; y++)
{
- register const Quantum
+ const Quantum
*magick_restrict p;
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
@@ -4116,7 +4131,7 @@ RestoreMSCWarning
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
- register const Quantum
+ const Quantum
*magick_restrict p;
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
@@ -4135,7 +4150,7 @@ RestoreMSCWarning
}
for (y=0; y < (ssize_t) image->rows; y++)
{
- register const Quantum
+ const Quantum
*magick_restrict p;
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
@@ -4154,7 +4169,7 @@ RestoreMSCWarning
}
for (y=0; y < (ssize_t) image->rows; y++)
{
- register const Quantum
+ const Quantum
*magick_restrict p;
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
@@ -4174,7 +4189,7 @@ RestoreMSCWarning
if (image->alpha_trait != UndefinedPixelTrait)
for (y=0; y < (ssize_t) image->rows; y++)
{
- register const Quantum
+ const Quantum
*magick_restrict p;
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
@@ -4208,7 +4223,7 @@ RestoreMSCWarning
(void) TransformImageColorspace(image,CMYKColorspace,exception);
for (y=0; y < (ssize_t) image->rows; y++)
{
- register const Quantum
+ const Quantum
*magick_restrict p;
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
@@ -4287,7 +4302,7 @@ RestoreMSCWarning
quantum_type=GrayQuantum;
for (y=0; y < (ssize_t) image->rows; y++)
{
- register const Quantum
+ const Quantum
*magick_restrict p;
p=GetVirtualPixels(image,0,y,image->columns,1,exception);