libtiff: TIFFSetSubDirectory(): call _TIFFCleanupIFDOffsetAndNumberMaps()

From 47591619e1e5a7041787c25df88cc9af344972d6 Mon Sep 17 00:00:00 2001
From: Even Rouault <[EMAIL REDACTED]>
Date: Fri, 6 Jan 2023 15:19:40 +0100
Subject: [PATCH] TIFFSetSubDirectory(): call
 _TIFFCleanupIFDOffsetAndNumberMaps()

---
 libtiff/tif_dir.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libtiff/tif_dir.c b/libtiff/tif_dir.c
index 396fbd93..4a3211e2 100644
--- a/libtiff/tif_dir.c
+++ b/libtiff/tif_dir.c
@@ -2105,6 +2105,7 @@ int TIFFSetSubDirectory(TIFF *tif, uint64_t diroff)
         /* Reset IFD list to start new one for SubIFD chain and also start
          * SubIFD chain with tif_curdir=0. */
         tif->tif_dirnumber = 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);