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

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