Skip to content

Commit

Permalink
GTiff: avoid doing unsigned integer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Mar 14, 2024
1 parent ec05413 commit 11fe8e4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions frmts/gtiff/gtiffdataset_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7314,8 +7314,11 @@ GDALDataset *GTiffDataset::CreateCopy(const char *pszFilename,
GTiffFillStreamableOffsetAndCount(l_hTIFF, nSize);
TIFFWriteDirectory(l_hTIFF);
}
TIFFSetDirectory(l_hTIFF,
static_cast<tdir_t>(TIFFNumberOfDirectories(l_hTIFF) - 1));
const auto nDirCount = TIFFNumberOfDirectories(l_hTIFF);
if (nDirCount >= 1)
{
TIFFSetDirectory(l_hTIFF, static_cast<tdir_t>(nDirCount - 1));
}
const toff_t l_nDirOffset = TIFFCurrentDirOffset(l_hTIFF);
TIFFFlush(l_hTIFF);
XTIFFClose(l_hTIFF);
Expand Down

0 comments on commit 11fe8e4

Please sign in to comment.