Blame SOURCES/libtiff-unknown-fix.patch

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