d00bc4
Make tiffdump more paranoid about checking the count field of a directory
d00bc4
entry.
d00bc4
d00bc4
Filed upstream at http://bugzilla.maptools.org/show_bug.cgi?id=2218
d00bc4
d00bc4
d00bc4
diff -Naur tiff-3.9.4.orig/tools/tiffdump.c tiff-3.9.4/tools/tiffdump.c
d00bc4
--- tiff-3.9.4.orig/tools/tiffdump.c	2010-06-08 14:50:44.000000000 -0400
d00bc4
+++ tiff-3.9.4/tools/tiffdump.c	2010-06-22 12:51:42.207932477 -0400
d00bc4
@@ -46,6 +46,7 @@
d00bc4
 # include <io.h>
d00bc4
 #endif
d00bc4
 
d00bc4
+#include "tiffiop.h"
d00bc4
 #include "tiffio.h"
d00bc4
 
d00bc4
 #ifndef O_BINARY
d00bc4
@@ -317,7 +318,7 @@
d00bc4
 			printf(">\n");
d00bc4
 			continue;
d00bc4
 		}
d00bc4
-		space = dp->tdir_count * datawidth[dp->tdir_type];
d00bc4
+		space = TIFFSafeMultiply(int, dp->tdir_count, datawidth[dp->tdir_type]);
d00bc4
 		if (space <= 0) {
d00bc4
 			printf(">\n");
d00bc4
 			Error("Invalid count for tag %u", dp->tdir_tag);
d00bc4
@@ -709,7 +710,7 @@
d00bc4
 	w = (dir->tdir_type < NWIDTHS ? datawidth[dir->tdir_type] : 0);
d00bc4
 	cc = dir->tdir_count * w;
d00bc4
 	if (lseek(fd, (off_t)dir->tdir_offset, 0) != (off_t)-1
d00bc4
-	    && read(fd, cp, cc) != -1) {
d00bc4
+	    && read(fd, cp, cc) == cc) {
d00bc4
 		if (swabflag) {
d00bc4
 			switch (dir->tdir_type) {
d00bc4
 			case TIFF_SHORT: