Blame SOURCES/libtiff-CVE-2011-1167.patch

0e6869
Upstream patch for CVE-2011-1167, heap-based buffer overflow in thunder
0e6869
decoder (ZDI-CAN-1004).
0e6869
0e6869
0e6869
diff -Naur tiff-3.9.4.orig/libtiff/tif_thunder.c tiff-3.9.4/libtiff/tif_thunder.c
0e6869
--- tiff-3.9.4.orig/libtiff/tif_thunder.c	2010-06-08 14:50:43.000000000 -0400
0e6869
+++ tiff-3.9.4/libtiff/tif_thunder.c	2011-03-18 12:17:13.635796403 -0400
0e6869
@@ -55,12 +55,32 @@
0e6869
 static const int twobitdeltas[4] = { 0, 1, 0, -1 };
0e6869
 static const int threebitdeltas[8] = { 0, 1, 2, 3, 0, -3, -2, -1 };
0e6869
 
0e6869
-#define	SETPIXEL(op, v) { \
0e6869
-	lastpixel = (v) & 0xf; \
0e6869
-	if (npixels++ & 1) \
0e6869
-	    *op++ |= lastpixel; \
0e6869
-	else \
0e6869
+#define	SETPIXEL(op, v) {                     \
0e6869
+	lastpixel = (v) & 0xf;                \
0e6869
+        if ( npixels < maxpixels )         \
0e6869
+        {                                     \
0e6869
+	  if (npixels++ & 1)                  \
0e6869
+	    *op++ |= lastpixel;               \
0e6869
+	  else                                \
0e6869
 	    op[0] = (tidataval_t) (lastpixel << 4); \
0e6869
+        }                                     \
0e6869
+}
0e6869
+
0e6869
+static int
0e6869
+ThunderSetupDecode(TIFF* tif)
0e6869
+{
0e6869
+	static const char module[] = "ThunderSetupDecode";
0e6869
+
0e6869
+        if( tif->tif_dir.td_bitspersample != 4 )
0e6869
+        {
0e6869
+                TIFFErrorExt(tif->tif_clientdata, module,
0e6869
+                             "Wrong bitspersample value (%d), Thunder decoder only supports 4bits per sample.",
0e6869
+                             (int) tif->tif_dir.td_bitspersample );
0e6869
+                return 0;
0e6869
+        }
0e6869
+        
0e6869
+
0e6869
+	return (1);
0e6869
 }
0e6869
 
0e6869
 static int
0e6869
@@ -151,6 +171,7 @@
0e6869
 	(void) scheme;
0e6869
 	tif->tif_decoderow = ThunderDecodeRow;
0e6869
 	tif->tif_decodestrip = ThunderDecodeRow;
0e6869
+	tif->tif_setupdecode = ThunderSetupDecode;
0e6869
 	return (1);
0e6869
 }
0e6869
 #endif /* THUNDER_SUPPORT */