8ca2e9
Teach "tiffinfo -D" to not try to print image data inside an EXIF subdirectory,
8ca2e9
because there isn't any.  Back-patched from an upstream 4.0.2 fix.
8ca2e9
8ca2e9
This is not a security issue in itself (it crashes, but with a simple NULL
8ca2e9
pointer dereference).  However, our test case for CVE-2012-5581 tickles this
8ca2e9
bug, so it seems easier to fix this than make a new test case.
8ca2e9
8ca2e9
8ca2e9
diff -Naur tiff-3.9.4.orig/tools/tiffinfo.c tiff-3.9.4/tools/tiffinfo.c
8ca2e9
--- tiff-3.9.4.orig/tools/tiffinfo.c	2010-06-08 14:50:44.000000000 -0400
8ca2e9
+++ tiff-3.9.4/tools/tiffinfo.c	2012-12-11 16:33:17.062228558 -0500
8ca2e9
@@ -49,7 +49,7 @@
8ca2e9
 int	stoponerr = 1;			/* stop on first read error */
8ca2e9
 
8ca2e9
 static	void usage(void);
8ca2e9
-static	void tiffinfo(TIFF*, uint16, long);
8ca2e9
+static	void tiffinfo(TIFF*, uint16, long, int);
8ca2e9
 
8ca2e9
 int
8ca2e9
 main(int argc, char* argv[])
8ca2e9
@@ -124,19 +124,20 @@
8ca2e9
 		if (tif != NULL) {
8ca2e9
 			if (dirnum != -1) {
8ca2e9
 				if (TIFFSetDirectory(tif, (tdir_t) dirnum))
8ca2e9
-					tiffinfo(tif, order, flags);
8ca2e9
+					tiffinfo(tif, order, flags, 1);
8ca2e9
 			} else if (diroff != 0) {
8ca2e9
 				if (TIFFSetSubDirectory(tif, diroff))
8ca2e9
-					tiffinfo(tif, order, flags);
8ca2e9
+					tiffinfo(tif, order, flags, 1);
8ca2e9
 			} else {
8ca2e9
 				do {
8ca2e9
 					uint32 offset;
8ca2e9
 
8ca2e9
-					tiffinfo(tif, order, flags);
8ca2e9
+					tiffinfo(tif, order, flags, 1);
8ca2e9
 					if (TIFFGetField(tif, TIFFTAG_EXIFIFD,
8ca2e9
 							 &offset)) {
8ca2e9
-						if (TIFFReadEXIFDirectory(tif, offset))
8ca2e9
-							tiffinfo(tif, order, flags);
8ca2e9
+						if (TIFFReadEXIFDirectory(tif, offset)) {
8ca2e9
+							tiffinfo(tif, order, flags, 0);
8ca2e9
+						}
8ca2e9
 					}
8ca2e9
 				} while (TIFFReadDirectory(tif));
8ca2e9
 			}
8ca2e9
@@ -426,10 +427,10 @@
8ca2e9
 }
8ca2e9
 
8ca2e9
 static void
8ca2e9
-tiffinfo(TIFF* tif, uint16 order, long flags)
8ca2e9
+tiffinfo(TIFF* tif, uint16 order, long flags, int is_image)
8ca2e9
 {
8ca2e9
 	TIFFPrintDirectory(tif, stdout, flags);
8ca2e9
-	if (!readdata)
8ca2e9
+	if (!readdata || !is_image)
8ca2e9
 		return;
8ca2e9
 	if (rawdata) {
8ca2e9
 		if (order) {