Skip to content

Commit

Permalink
third_party/libertiff: tileCoordinateToIdx(): avoid potential harmles…
Browse files Browse the repository at this point in the history
…s unsigned-int-overflow (ossfuzz#397740496)
  • Loading branch information
rouault committed Feb 19, 2025
1 parent b51894d commit dd00fc4
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 dd00fc4

Please sign in to comment.