Skip to content

Commit

Permalink
RawRasterBand::Initialize(): avoid integer overflow. Fixes https://bu…
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Nov 11, 2019
1 parent d5bc291 commit 836e617
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gdal/gcore/rawdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,16 @@ void RawRasterBand::Initialize()
vsi_l_offset nLargestOffset = nImgOffset;
if( nLineOffset < 0 )
{
if( static_cast<vsi_l_offset>(-nLineOffset) * (nRasterYSize - 1) > nImgOffset )
const auto nDelta = static_cast<vsi_l_offset>(
-static_cast<GIntBig>(nLineOffset)) * (nRasterYSize - 1);
if( nDelta > nImgOffset )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Inconsistent nLineOffset, nRasterYSize and nImgOffset");
pLineBuffer = nullptr;
return;
}
nSmallestOffset -= static_cast<vsi_l_offset>(-nLineOffset) * (nRasterYSize - 1);
nSmallestOffset -= nDelta;
}
else
{
Expand All @@ -225,7 +227,8 @@ void RawRasterBand::Initialize()
}
if( nPixelOffset < 0 )
{
if( static_cast<vsi_l_offset>(-nPixelOffset) * (nRasterXSize - 1) > nSmallestOffset )
if( static_cast<vsi_l_offset>(-static_cast<GIntBig>(nPixelOffset)) *
(nRasterXSize - 1) > nSmallestOffset )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Inconsistent nPixelOffset, nRasterXSize and nImgOffset");
Expand Down

0 comments on commit 836e617

Please sign in to comment.