Blame SOURCES/libtiff-unknown-fix.patch

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