Skip to content

Commit

Permalink
Merge pull request OSGeo#11872 from rouault/fix_ossfuzz_397740496
Browse files Browse the repository at this point in the history
third_party/libertiff: tileCoordinateToIdx(): avoid potential harmless unsigned-int-overflow (ossfuzz#397740496)
  • Loading branch information
rouault authored Feb 20, 2025
2 parents b51894d + dd00fc4 commit 26fc9a3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions third_party/libertiff/libertiff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,18 +1084,26 @@ class Image
{
if (m_isTiled && m_tileWidth > 0 && m_tileHeight > 0)
{
const auto lTilesPerRow = tilesPerRow();
const auto lTilesPerCol = tilesPerCol();
const uint32_t lTilesPerRow = tilesPerRow();
const uint32_t lTilesPerCol = tilesPerCol();
if (xtile >= lTilesPerRow || ytile >= lTilesPerCol)
{
ok = false;
return 0;
}
auto idx = uint64_t(ytile) * lTilesPerRow + xtile;
uint64_t idx = uint64_t(ytile) * lTilesPerRow + xtile;
if (bandIdx &&
m_planarConfiguration == PlanarConfiguration::Separate)
{
idx += uint64_t(bandIdx) * lTilesPerCol * lTilesPerRow;
const uint64_t lTotalTiles =
uint64_t(lTilesPerCol) * lTilesPerRow;
if (lTotalTiles >
std::numeric_limits<uint64_t>::max() / bandIdx)
{
ok = false;
return 0;
}
idx += bandIdx * lTotalTiles;
}
return idx;
}
Expand Down

0 comments on commit 26fc9a3

Please sign in to comment.