1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
From: Cristy <mikayla-grace@urban-warrior.org>
Date: Sat, 6 Nov 2021 09:01:26 -0400
Subject: early exit on exception
In case of malformed tiff image bail early
origin: https://github.com/ImageMagick/ImageMagick6/commit/b272acab91444f2115099fe51ee6c91bb4db5d50
(cherry picked from commit b272acab91444f2115099fe51ee6c91bb4db5d50)
---
coders/tiff.c | 44 +++++++++++++++++++++++++++++++++-----------
1 file changed, 33 insertions(+), 11 deletions(-)
diff --git a/coders/tiff.c b/coders/tiff.c
index e650f23..fbc6980 100644
--- a/coders/tiff.c
+++ b/coders/tiff.c
@@ -1184,7 +1184,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
*image;
int
- tiff_status;
+ tiff_status = 0;
MagickBooleanType
more_frames;
@@ -2019,7 +2019,9 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
columns_remaining=image->columns-x;
if ((ssize_t) (x+columns) < (ssize_t) image->columns)
columns_remaining=columns;
- if (TIFFReadTile(tiff,tile_pixels,(uint32) x,(uint32) y,0,i) == -1)
+ tiff_status=TIFFReadTile(tiff,tile_pixels,(uint32) x,(uint32) y,
+ 0,i);
+ if (tiff_status == -1)
break;
p=tile_pixels;
for (row=0; row < rows_remaining; row++)
@@ -2079,9 +2081,9 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
if (generic_info == (MemoryInfo *) NULL)
ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
pixels=(uint32 *) GetVirtualMemoryBlob(generic_info);
- status=TIFFReadRGBAImage(tiff,(uint32) image->columns,(uint32)
+ tiff_status=TIFFReadRGBAImage(tiff,(uint32) image->columns,(uint32)
image->rows,(uint32 *) pixels,0);
- if (status == -1)
+ if (tiff_status == -1)
{
generic_info=RelinquishVirtualMemory(generic_info);
break;
@@ -2130,6 +2132,11 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
next_tiff_frame:
if (quantum_info != (QuantumInfo *) NULL)
quantum_info=DestroyQuantumInfo(quantum_info);
+ if (tiff_status == -1)
+ {
+ status=MagickFalse;
+ break;
+ }
if (photometric == PHOTOMETRIC_CIELAB)
DecodeLabImage(image,exception);
if ((photometric == PHOTOMETRIC_LOGL) ||
@@ -3191,6 +3198,9 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,
EndianType
endian_type;
+ int
+ tiff_status = 0;
+
MagickBooleanType
debug,
status;
@@ -3870,7 +3880,8 @@ RestoreMSCWarning
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,quantum_type,pixels,&image->exception);
- if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)
+ tiff_status=TIFFWritePixels(tiff,&tiff_info,y,0,image);
+ if (tiff_status == -1)
break;
if (image->previous == (Image *) NULL)
{
@@ -3898,7 +3909,8 @@ RestoreMSCWarning
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,RedQuantum,pixels,&image->exception);
- if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)
+ tiff_status=TIFFWritePixels(tiff,&tiff_info,y,0,image);
+ if (tiff_status == -1)
break;
}
if (image->previous == (Image *) NULL)
@@ -3917,7 +3929,8 @@ RestoreMSCWarning
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,GreenQuantum,pixels,&image->exception);
- if (TIFFWritePixels(tiff,&tiff_info,y,1,image) == -1)
+ tiff_status=TIFFWritePixels(tiff,&tiff_info,y,1,image);
+ if (tiff_status == -1)
break;
}
if (image->previous == (Image *) NULL)
@@ -3936,7 +3949,8 @@ RestoreMSCWarning
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,BlueQuantum,pixels,&image->exception);
- if (TIFFWritePixels(tiff,&tiff_info,y,2,image) == -1)
+ tiff_status=TIFFWritePixels(tiff,&tiff_info,y,2,image);
+ if (tiff_status == -1)
break;
}
if (image->previous == (Image *) NULL)
@@ -3957,7 +3971,8 @@ RestoreMSCWarning
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,AlphaQuantum,pixels,&image->exception);
- if (TIFFWritePixels(tiff,&tiff_info,y,3,image) == -1)
+ tiff_status=TIFFWritePixels(tiff,&tiff_info,y,3,image);
+ if (tiff_status == -1)
break;
}
if (image->previous == (Image *) NULL)
@@ -3991,7 +4006,8 @@ RestoreMSCWarning
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,quantum_type,pixels,&image->exception);
- if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)
+ tiff_status=TIFFWritePixels(tiff,&tiff_info,y,0,image);
+ if (tiff_status == -1)
break;
if (image->previous == (Image *) NULL)
{
@@ -4070,7 +4086,8 @@ RestoreMSCWarning
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,quantum_type,pixels,&image->exception);
- if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)
+ tiff_status=TIFFWritePixels(tiff,&tiff_info,y,0,image);
+ if (tiff_status == -1)
break;
if (image->previous == (Image *) NULL)
{
@@ -4087,6 +4104,11 @@ RestoreMSCWarning
if (image->colorspace == LabColorspace)
DecodeLabImage(image,&image->exception);
DestroyTIFFInfo(&tiff_info);
+ if (tiff_status == -1)
+ {
+ status=MagickFalse;
+ break;
+ }
/* TIFFPrintDirectory(tiff,stdout,MagickFalse); */
if (TIFFWriteDirectory(tiff) == 0)
{
|