From 99edc607e2dd8b896072de0d3327d90e4fbfdf9d Mon Sep 17 00:00:00 2001 From: Cristy Date: Sun, 4 Sep 2016 11:30:32 -0400 Subject: [PATCH] https://github.com/ImageMagick/ImageMagick/issues/262 --- coders/tiff.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/coders/tiff.c b/coders/tiff.c index 4d0334b62..b2be73665 100644 --- a/coders/tiff.c +++ b/coders/tiff.c @@ -3002,7 +3002,7 @@ static void TIFFSetProperties(TIFF *tiff,const ImageInfo *image_info, uint16 page, pages; - + page=(uint16) image->scene; pages=(uint16) GetImageListLength(image); if ((image_info->adjoin != MagickFalse) && (pages > 1)) @@ -3499,7 +3499,7 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, MagickStatusType flags; - rows_per_strip+=(16-(rows_per_strip % 16)); + rows_per_strip=16*(((rows_per_strip < 16 ? 16 : rows_per_strip)+1)/16); if (image_info->quality != UndefinedCompressionQuality) (void) TIFFSetField(tiff,TIFFTAG_JPEGQUALITY,image_info->quality); (void) TIFFSetField(tiff,TIFFTAG_JPEGCOLORMODE,JPEGCOLORMODE_RAW); @@ -3539,7 +3539,8 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, } case COMPRESSION_ADOBE_DEFLATE: { - rows_per_strip=(uint32) image->rows; + if (((32*1024)/MagickMax(TIFFScanlineSize(tiff),1)) > rows_per_strip) + rows_per_strip=((32*1024)/MagickMax(TIFFScanlineSize(tiff),1)); (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE, &bits_per_sample); if (((photometric == PHOTOMETRIC_RGB) || @@ -3556,18 +3557,31 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, /* Byte-aligned EOL. */ - rows_per_strip=(uint32) image->rows; + rows_per_strip=(16*1024*1024UL)/image->columns; + if (rows_per_strip < 1) + rows_per_strip=1; + if (rows_per_strip > image->rows) + rows_per_strip=(uint32) image->rows; (void) TIFFSetField(tiff,TIFFTAG_GROUP3OPTIONS,4); break; } case COMPRESSION_CCITTFAX4: { - rows_per_strip=(uint32) image->rows; + rows_per_strip=(16*1024*1024UL)/image->columns; + if (rows_per_strip < 1) + rows_per_strip=1; + if (rows_per_strip > image->rows) + rows_per_strip=(uint32) image->rows; break; } #if defined(LZMA_SUPPORT) && defined(COMPRESSION_LZMA) case COMPRESSION_LZMA: { + rows_per_strip=(16*1024*1024UL)/image->columns; + if (rows_per_strip < 1) + rows_per_strip=1; + if (rows_per_strip > image->rows) + rows_per_strip=(uint32) image->rows; if (((photometric == PHOTOMETRIC_RGB) || (photometric == PHOTOMETRIC_MINISBLACK)) && ((bits_per_sample == 8) || (bits_per_sample == 16))) -- 2.40.0