Blame SOURCES/libtiff-CVE-2015-8683_8665.patch

460672
diff --git a/libtiff/tif_getimage.c b/libtiff/tif_getimage.c
460672
index 1633325..018351b 100644
460672
--- a/libtiff/tif_getimage.c
460672
+++ b/libtiff/tif_getimage.c
460672
@@ -182,8 +182,25 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
460672
 				    "Planarconfiguration", td->td_planarconfig);
460672
 				return (0);
460672
 			}
460672
+			if( td->td_samplesperpixel != 3 || colorchannels != 3 )
460672
+            {
460672
+                 sprintf(emsg,
460672
+                        "Sorry, can not handle image with %s=%d, %s=%d",
460672
+                        "Samples/pixel", td->td_samplesperpixel,
460672
+                        "colorchannels", colorchannels);
460672
+                 return 0;
460672
+             }
460672
 			break;
460672
 		case PHOTOMETRIC_CIELAB:
460672
+            if( td->td_samplesperpixel != 3 || colorchannels != 3 || td->td_bitspersample != 8 )
460672
+             {
460672
+                 sprintf(emsg,
460672
+                        "Sorry, can not handle image with %s=%d, %s=%d and %s=%d",
460672
+                         "Samples/pixel", td->td_samplesperpixel,
460672
+                         "colorchannels", colorchannels,
460672
+                         "Bits/sample", td->td_bitspersample);
460672
+                 return 0;
460672
+             }
460672
 			break;
460672
 		default:
460672
 			sprintf(emsg, "Sorry, can not handle image with %s=%d",
460672
@@ -241,6 +258,9 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024])
460672
 	uint16 *red_orig, *green_orig, *blue_orig;
460672
 	int n_color;
460672
 
460672
+	if( !TIFFRGBAImageOK(tif, emsg) )
460672
+		return 0;
460672
+
460672
 	/* Initialize to normal values */
460672
 	img->row_offset = 0;
460672
 	img->col_offset = 0;
460672
@@ -2453,29 +2473,33 @@ PickContigCase(TIFFRGBAImage* img)
460672
 		case PHOTOMETRIC_RGB:
460672
 			switch (img->bitspersample) {
460672
 				case 8:
460672
-					if (img->alpha == EXTRASAMPLE_ASSOCALPHA)
460672
+					if (img->alpha == EXTRASAMPLE_ASSOCALPHA &&
460672
+						img->samplesperpixel >= 4)
460672
 						img->put.contig = putRGBAAcontig8bittile;
460672
-					else if (img->alpha == EXTRASAMPLE_UNASSALPHA)
460672
+					else if (img->alpha == EXTRASAMPLE_UNASSALPHA &&
460672
+							 img->samplesperpixel >= 4)
460672
 					{
460672
 						if (BuildMapUaToAa(img))
460672
 							img->put.contig = putRGBUAcontig8bittile;
460672
 					}
460672
-					else
460672
+					else if( img->samplesperpixel >= 3 )
460672
 						img->put.contig = putRGBcontig8bittile;
460672
 					break;
460672
 				case 16:
460672
-					if (img->alpha == EXTRASAMPLE_ASSOCALPHA)
460672
+					if (img->alpha == EXTRASAMPLE_ASSOCALPHA &&
460672
+						img->samplesperpixel >=4 )
460672
 					{
460672
 						if (BuildMapBitdepth16To8(img))
460672
 							img->put.contig = putRGBAAcontig16bittile;
460672
 					}
460672
-					else if (img->alpha == EXTRASAMPLE_UNASSALPHA)
460672
+					else if (img->alpha == EXTRASAMPLE_UNASSALPHA &&
460672
+							 img->samplesperpixel >=4 )
460672
 					{
460672
 						if (BuildMapBitdepth16To8(img) &&
460672
 						    BuildMapUaToAa(img))
460672
 							img->put.contig = putRGBUAcontig16bittile;
460672
 					}
460672
-					else
460672
+					else if( img->samplesperpixel >=3 )
460672
 					{
460672
 						if (BuildMapBitdepth16To8(img))
460672
 							img->put.contig = putRGBcontig16bittile;
460672
@@ -2484,7 +2508,7 @@ PickContigCase(TIFFRGBAImage* img)
460672
 			}
460672
 			break;
460672
 		case PHOTOMETRIC_SEPARATED:
460672
-			if (buildMap(img)) {
460672
+			if (img->samplesperpixel >=4 && buildMap(img)) {
460672
 				if (img->bitspersample == 8) {
460672
 					if (!img->Map)
460672
 						img->put.contig = putRGBcontig8bitCMYKtile;
460672
@@ -2580,7 +2604,7 @@ PickContigCase(TIFFRGBAImage* img)
460672
 			}
460672
 			break;
460672
 		case PHOTOMETRIC_CIELAB:
460672
-			if (buildMap(img)) {
460672
+			if (img->samplesperpixel == 3 && buildMap(img)) {
460672
 				if (img->bitspersample == 8)
460672
 					img->put.contig = initCIELabConversion(img);
460672
 				break;