Huge TIFF conversion - Interger overflow - IM:7.0.4.5
Posted: 2017-01-24T03:35:43-07:00
Cheers!
I have run into a problem with huge TIFF files compressed with LZW.
The example file is mainly white with black pixels. It's size is ~90MB (19046x49704). I do also have larger files and all of them compressed with LZW.
When trying to rotate the image:
or trying to decompress the image:
An error accours:
I have downloaded the sources of ImageMagick (https://www.imagemagick.org/script/install-source.php) and came into the following conclusion when working with VisualMagick:
In file: tif_strip.c there is a method in line: 220: TIFFStripSize :
it throws the exception in line 230.
The exception is being thrown because the cast in line 227 fails:
The value of m is the result of uint64 TIFFStripSize64 but is casted to tmsize_t which is signed int
The tmsize_t is defined in tiffconf.h in line 38:
The strip is huge and is calculated correctly, but cannot be casted to signed int if is greater than the maximum int value. The cast is true if run on a 32bit operating system. But I am running Windows10 64bit and decided to test another aproach:
I cannot define unsigned long permanently because the result of TIFFStripSize is used in file: tif_write.c:660 and is passed as a value of parameter to _TIFFmalloc (tif_unix.c:311) . If running on 32Bit system I can not request more than allowed memory for object so I've decided to keep the #ifdef _WIN64.
By this I have allowed the system to create files that have huge strips. Unfortunatelly Windows is unable to show or create a preview thumb of the output image, and also is unable to show its properties. I believe that this is because I have probably broken a TIFF RFC, haven't I? But still the output image is 120MB in size after rotation and is shown properly in IrfanView and PhotoShop, and can also be rotated and scaled by ImageMagick.
So the question is:
Is the original file corrupted or is there a bug in ImageMagick or what?
Attached you can find a dump from exiftool with information about the StipByteCounts and StripOffsets:
http://pastebin.com/PkSWMh2Y
Regards!
I have run into a problem with huge TIFF files compressed with LZW.
The example file is mainly white with black pixels. It's size is ~90MB (19046x49704). I do also have larger files and all of them compressed with LZW.
When trying to rotate the image:
Code: Select all
convert.exe "input.tif" -virtual-pixel Background -background "#000000" +distort SRT "0,0 90.2291806734696" +repage "output.tif"
Code: Select all
convert.exe image.tif -compress none out_image.tif
The file seems not to be corrupted - it is opened properly in Photoshop and IrfanView, but ImageMagick and Paint.Net do have problems with processing this file.TIFFStripSize Integer overflow
I have downloaded the sources of ImageMagick (https://www.imagemagick.org/script/install-source.php) and came into the following conclusion when working with VisualMagick:
In file: tif_strip.c there is a method in line: 220: TIFFStripSize :
Code: Select all
tmsize_t
TIFFStripSize(TIFF* tif)
{
static const char module[] = "TIFFStripSize";
uint64 m;
tmsize_t n;
m=TIFFStripSize64(tif);
n=(tmsize_t)m;
if ((uint64)n!=m)
{
TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");
n=0;
}
return(n);
}
Code: Select all
TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");
Code: Select all
n=(tmsize_t)m;
The tmsize_t is defined in tiffconf.h in line 38:
Code: Select all
#define TIFF_SSIZE_T signed int
Code: Select all
#ifdef _WIN64
#define TIFF_SSIZE_T unsigned long
#else
#define TIFF_SSIZE_T signed int
#endif
By this I have allowed the system to create files that have huge strips. Unfortunatelly Windows is unable to show or create a preview thumb of the output image, and also is unable to show its properties. I believe that this is because I have probably broken a TIFF RFC, haven't I? But still the output image is 120MB in size after rotation and is shown properly in IrfanView and PhotoShop, and can also be rotated and scaled by ImageMagick.
So the question is:
Is the original file corrupted or is there a bug in ImageMagick or what?
Attached you can find a dump from exiftool with information about the StipByteCounts and StripOffsets:
http://pastebin.com/PkSWMh2Y
Regards!