From b8b12c44c1a8c622fc98f8e76f66e5e5edac3b8e Mon Sep 17 00:00:00 2001
From: Even Rouault <[EMAIL REDACTED]>
Date: Sun, 26 Mar 2023 16:27:40 +0200
Subject: [PATCH] tif_ovrcache.c: check TIFFSetSubDirectory() return value (CID
1524573)
---
contrib/addtiffo/tif_ovrcache.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/contrib/addtiffo/tif_ovrcache.c b/contrib/addtiffo/tif_ovrcache.c
index 4153189b..9cbf09d1 100644
--- a/contrib/addtiffo/tif_ovrcache.c
+++ b/contrib/addtiffo/tif_ovrcache.c
@@ -43,6 +43,7 @@ TIFFOvrCache *TIFFCreateOvrCache(TIFF *hTIFF, toff_t nDirOffset)
{
TIFFOvrCache *psCache;
toff_t nBaseDirOffset;
+ int nRet;
psCache = (TIFFOvrCache *)_TIFFmalloc(sizeof(TIFFOvrCache));
psCache->nDirOffset = nDirOffset;
@@ -52,7 +53,9 @@ TIFFOvrCache *TIFFCreateOvrCache(TIFF *hTIFF, toff_t nDirOffset)
/* Get definition of this raster from the TIFF file itself. */
/* -------------------------------------------------------------------- */
nBaseDirOffset = TIFFCurrentDirOffset(psCache->hTIFF);
- TIFFSetSubDirectory(hTIFF, nDirOffset);
+ nRet = TIFFSetSubDirectory(hTIFF, nDirOffset);
+ (void)nRet;
+ assert(nRet == 1);
TIFFGetField(hTIFF, TIFFTAG_IMAGEWIDTH, &(psCache->nXSize));
TIFFGetField(hTIFF, TIFFTAG_IMAGELENGTH, &(psCache->nYSize));
@@ -120,7 +123,9 @@ TIFFOvrCache *TIFFCreateOvrCache(TIFF *hTIFF, toff_t nDirOffset)
psCache->nBlockOffset = 0;
- TIFFSetSubDirectory(psCache->hTIFF, nBaseDirOffset);
+ nRet = TIFFSetSubDirectory(psCache->hTIFF, nBaseDirOffset);
+ (void)nRet;
+ assert(nRet == 1);
return psCache;
}