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