Skip to content

Commit

Permalink
ERS: avoid CodeQL cpp/comparison-with-wider-type
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 9, 2024
1 parent 8dffa34 commit 279d858
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions frmts/ers/ersdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,14 +1075,15 @@ GDALDataset *ERSDataset::Open(GDALOpenInfo *poOpenInfo)
if (!RAWDatasetCheckMemoryUsage(
poDS->nRasterXSize, poDS->nRasterYSize, nBands, iWordSize,
iWordSize, iWordSize * nBands * poDS->nRasterXSize,
nHeaderOffset, iWordSize * poDS->nRasterXSize,
nHeaderOffset,
static_cast<vsi_l_offset>(iWordSize) * poDS->nRasterXSize,
poDS->fpImage))
{
return nullptr;
}
if (nHeaderOffset >
std::numeric_limits<GIntBig>::max() -
(nBands - 1) * iWordSize * poDS->nRasterXSize)
if (nHeaderOffset > std::numeric_limits<GIntBig>::max() -
static_cast<GIntBig>(nBands - 1) *
iWordSize * poDS->nRasterXSize)
{
CPLError(CE_Failure, CPLE_AppDefined,
"int overflow: too large nHeaderOffset");
Expand All @@ -1094,7 +1095,8 @@ GDALDataset *ERSDataset::Open(GDALOpenInfo *poOpenInfo)
// Assume pixel interleaved.
auto poBand = std::make_unique<ERSRasterBand>(
poDS.get(), iBand + 1, poDS->fpImage,
nHeaderOffset + iWordSize * iBand * poDS->nRasterXSize,
nHeaderOffset + static_cast<vsi_l_offset>(iWordSize) *
iBand * poDS->nRasterXSize,
iWordSize, iWordSize * nBands * poDS->nRasterXSize, eType,
bNative);
if (!poBand->IsValid())
Expand Down

0 comments on commit 279d858

Please sign in to comment.