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