From 95994b65ea6536ebd9d829d2fbb5e889760c86ab Mon Sep 17 00:00:00 2001
From: Manuel Massing <[EMAIL REDACTED]>
Date: Wed, 25 Oct 2023 15:35:40 +0200
Subject: [PATCH] #618: ensure absolute seeking is forced independent of
TIFFReadDirectory success.
This fixes TIFFSetDirectory calls for the case where
TIFFReadDirectory was unsuccessful.
---
libtiff/tif_dir.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/libtiff/tif_dir.c b/libtiff/tif_dir.c
index 85006218..47ad21e0 100644
--- a/libtiff/tif_dir.c
+++ b/libtiff/tif_dir.c
@@ -2151,17 +2151,21 @@ int TIFFSetSubDirectory(TIFF *tif, uint64_t diroff)
else
tif->tif_curdir++;
}
- if (retval && probablySubIFD)
+ if (probablySubIFD)
{
- /* Reset IFD list to start new one for SubIFD chain and also start
- * SubIFD chain with tif_curdir=0. */
- _TIFFCleanupIFDOffsetAndNumberMaps(tif); /* invalidate IFD loop lists */
- tif->tif_curdir = 0; /* first directory of new chain */
- /* add this offset to new IFD list */
- _TIFFCheckDirNumberAndOffset(tif, tif->tif_curdir, diroff);
+ if (retval)
+ {
+ /* Reset IFD list to start new one for SubIFD chain and also start
+ * SubIFD chain with tif_curdir=0. */
+ _TIFFCleanupIFDOffsetAndNumberMaps(tif); /* invalidate IFD loop lists */
+ tif->tif_curdir = 0; /* first directory of new chain */
+ /* add this offset to new IFD list */
+ _TIFFCheckDirNumberAndOffset(tif, tif->tif_curdir, diroff);
+ }
/* To be able to return from SubIFD or custom-IFD to main-IFD */
tif->tif_setdirectory_force_absolute = TRUE;
}
+
return (retval);
}