Blame SOURCES/libtiff-CVE-2012-1173.patch

7c98bb
This patch is submitted to upstream for CVE-2012-1173
7c98bb
7c98bb
7c98bb
diff -Naur tiff-3.9.5.orig/libtiff/tif_getimage.c tiff-3.9.5/libtiff/tif_getimage.c
7c98bb
--- tiff-3.9.5.orig/libtiff/tif_getimage.c	2010-07-08 12:17:59.000000000 -0400
7c98bb
+++ tiff-3.9.5/libtiff/tif_getimage.c	2012-03-14 14:49:25.796728783 -0400
7c98bb
@@ -673,18 +673,24 @@
7c98bb
 	unsigned char* p2;
7c98bb
 	unsigned char* pa;
7c98bb
 	tsize_t tilesize;
7c98bb
+	tsize_t bufsize;
7c98bb
 	int32 fromskew, toskew;
7c98bb
 	int alpha = img->alpha;
7c98bb
 	uint32 nrow;
7c98bb
 	int ret = 1, flip;
7c98bb
 
7c98bb
 	tilesize = TIFFTileSize(tif);
7c98bb
-	buf = (unsigned char*) _TIFFmalloc((alpha?4:3)*tilesize);
7c98bb
+	bufsize = TIFFSafeMultiply(tsize_t,alpha?4:3,tilesize);
7c98bb
+	if (bufsize == 0) {
7c98bb
+		TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtTileSeparate");
7c98bb
+		return (0);
7c98bb
+	}
7c98bb
+	buf = (unsigned char*) _TIFFmalloc(bufsize);
7c98bb
 	if (buf == 0) {
7c98bb
 		TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer");
7c98bb
 		return (0);
7c98bb
 	}
7c98bb
-	_TIFFmemset(buf, 0, (alpha?4:3)*tilesize);
7c98bb
+	_TIFFmemset(buf, 0, bufsize);
7c98bb
 	p0 = buf;
7c98bb
 	p1 = p0 + tilesize;
7c98bb
 	p2 = p1 + tilesize;
7c98bb
@@ -880,17 +886,23 @@
7c98bb
 	uint32 rowsperstrip, offset_row;
7c98bb
 	uint32 imagewidth = img->width;
7c98bb
 	tsize_t stripsize;
7c98bb
+	tsize_t bufsize;
7c98bb
 	int32 fromskew, toskew;
7c98bb
 	int alpha = img->alpha;
7c98bb
 	int ret = 1, flip;
7c98bb
 
7c98bb
 	stripsize = TIFFStripSize(tif);
7c98bb
-	p0 = buf = (unsigned char *)_TIFFmalloc((alpha?4:3)*stripsize);
7c98bb
+	bufsize = TIFFSafeMultiply(tsize_t,alpha?4:3,stripsize);
7c98bb
+	if (bufsize == 0) {
7c98bb
+		TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtStripSeparate");
7c98bb
+		return (0);
7c98bb
+	}
7c98bb
+	p0 = buf = (unsigned char *)_TIFFmalloc(bufsize);
7c98bb
 	if (buf == 0) {
7c98bb
 		TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer");
7c98bb
 		return (0);
7c98bb
 	}
7c98bb
-	_TIFFmemset(buf, 0, (alpha?4:3)*stripsize);
7c98bb
+	_TIFFmemset(buf, 0, bufsize);
7c98bb
 	p1 = p0 + stripsize;
7c98bb
 	p2 = p1 + stripsize;
7c98bb
 	pa = (alpha?(p2+stripsize):NULL);
7c98bb
diff -Naur tiff-3.9.5.orig/libtiff/tiffiop.h tiff-3.9.5/libtiff/tiffiop.h
7c98bb
--- tiff-3.9.5.orig/libtiff/tiffiop.h	2011-03-28 09:43:43.000000000 -0400
7c98bb
+++ tiff-3.9.5/libtiff/tiffiop.h	2012-03-14 14:49:25.797728754 -0400
7c98bb
@@ -246,7 +246,7 @@
7c98bb
 #define	TIFFroundup(x, y) (TIFFhowmany(x,y)*(y))
7c98bb
 
7c98bb
 /* Safe multiply which returns zero if there is an integer overflow */
7c98bb
-#define TIFFSafeMultiply(t,v,m) ((((t)m != (t)0) && (((t)((v*m)/m)) == (t)v)) ? (t)(v*m) : (t)0)
7c98bb
+#define TIFFSafeMultiply(t,v,m) ((((t)(m) != (t)0) && (((t)(((v)*(m))/(m))) == (t)(v))) ? (t)((v)*(m)) : (t)0)
7c98bb
 
7c98bb
 #define TIFFmax(A,B) ((A)>(B)?(A):(B))
7c98bb
 #define TIFFmin(A,B) ((A)<(B)?(A):(B))