diff options
author | Even Rouault <even.rouault@spatialys.com> | 2023-02-16 22:46:38 +0000 |
---|---|---|
committer | Even Rouault <even.rouault@spatialys.com> | 2023-02-16 22:46:38 +0000 |
commit | 61656f921830513b7fffc1a991ba2c94d3202c4f (patch) | |
tree | f9f1834397f7c194a01ad5de4f5b3e1971ceb4dc | |
parent | d1f658afa5ab5ed21a9e32e0f790f41b01506cd9 (diff) | |
parent | 12ba27949b236ece918afafca757f7e30b1189d0 (diff) | |
download | libtiff-git-61656f921830513b7fffc1a991ba2c94d3202c4f.tar.gz |
Merge branch 'fix_Unlink_first_directory_0' into 'master'
Fix TIFFUnlinkDirectory(0) case and unlink of first directory.
See merge request libtiff/libtiff!460
-rw-r--r-- | libtiff/tif_dir.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libtiff/tif_dir.c b/libtiff/tif_dir.c index 8c275e04..56ecbf39 100644 --- a/libtiff/tif_dir.c +++ b/libtiff/tif_dir.c @@ -2143,6 +2143,13 @@ int TIFFUnlinkDirectory(TIFF *tif, tdir_t dirn) "Can not unlink directory in read-only file"); return (0); } + if (dirn == 0) + { + TIFFErrorExtR(tif, module, + "For TIFFUnlinkDirectory() first directory starts with " + "number 1 and not 0"); + return (0); + } /* * Go to the directory before the one we want * to unlink and nab the offset of the link @@ -2205,6 +2212,17 @@ int TIFFUnlinkDirectory(TIFF *tif, tdir_t dirn) return (0); } } + + /* For dirn=1 (first directory) also update the libtiff internal + * base offset variables. */ + if (dirn == 1) + { + if (!(tif->tif_flags & TIFF_BIGTIFF)) + tif->tif_header.classic.tiff_diroff = (uint32_t)nextdir; + else + tif->tif_header.big.tiff_diroff = nextdir; + } + /* * Leave directory state setup safely. We don't have * facilities for doing inserting and removing directories, |