d00bc4
Ooops, previous fix to unknown-tag handling caused TIFFReadDirectory to
d00bc4
sometimes complain about out-of-order tags when there weren't really any.
d00bc4
Fix by decoupling that logic from the tag search logic.
d00bc4
d00bc4
Filed upstream at http://bugzilla.maptools.org/show_bug.cgi?id=2210
d00bc4
d00bc4
d00bc4
diff -Naur tiff-3.9.4.orig/libtiff/tif_dirread.c tiff-3.9.4/libtiff/tif_dirread.c
d00bc4
--- tiff-3.9.4.orig/libtiff/tif_dirread.c	2010-06-14 10:27:51.000000000 -0400
d00bc4
+++ tiff-3.9.4/libtiff/tif_dirread.c	2010-06-16 01:27:03.000000000 -0400
d00bc4
@@ -83,6 +83,7 @@
d00bc4
 	const TIFFFieldInfo* fip;
d00bc4
 	size_t fix;
d00bc4
 	uint16 dircount;
d00bc4
+	uint16 previous_tag = 0;
d00bc4
 	int diroutoforderwarning = 0, compressionknown = 0;
d00bc4
 	int haveunknowntags = 0;
d00bc4
 
d00bc4
@@ -163,23 +164,24 @@
d00bc4
 
d00bc4
 		if (dp->tdir_tag == IGNORE)
d00bc4
 			continue;
d00bc4
-		if (fix >= tif->tif_nfields)
d00bc4
-			fix = 0;
d00bc4
 
d00bc4
 		/*
d00bc4
 		 * Silicon Beach (at least) writes unordered
d00bc4
 		 * directory tags (violating the spec).  Handle
d00bc4
 		 * it here, but be obnoxious (maybe they'll fix it?).
d00bc4
 		 */
d00bc4
-		if (dp->tdir_tag < tif->tif_fieldinfo[fix]->field_tag) {
d00bc4
+		if (dp->tdir_tag < previous_tag) {
d00bc4
 			if (!diroutoforderwarning) {
d00bc4
 				TIFFWarningExt(tif->tif_clientdata, module,
d00bc4
 	"%s: invalid TIFF directory; tags are not sorted in ascending order",
d00bc4
 					    tif->tif_name);
d00bc4
 				diroutoforderwarning = 1;
d00bc4
 			}
d00bc4
-			fix = 0;			/* O(n^2) */
d00bc4
 		}
d00bc4
+		previous_tag = dp->tdir_tag;
d00bc4
+		if (fix >= tif->tif_nfields ||
d00bc4
+		    dp->tdir_tag < tif->tif_fieldinfo[fix]->field_tag)
d00bc4
+			fix = 0;			/* O(n^2) */
d00bc4
 		while (fix < tif->tif_nfields &&
d00bc4
 		    tif->tif_fieldinfo[fix]->field_tag < dp->tdir_tag)
d00bc4
 			fix++;