Skip to content

Commit

Permalink
Merge pull request #11909 from rouault/fix_11905
Browse files Browse the repository at this point in the history
GDALResampleChunk_ConvolutionT(): avoid casting NaN to int64_t
  • Loading branch information
rouault authored Mar 4, 2025
2 parents cf9a904 + e6b9422 commit ef607a3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions gcore/overview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3142,7 +3142,10 @@ static CPLErr GDALResampleChunk_ConvolutionT(
: dfNoDataValue;
// cppcheck-suppress unreadVariable
const int isIntegerDT = GDALDataTypeIsInteger(dstDataType);
const auto nNodataValueInt64 = static_cast<GInt64>(dfNoDataValue);
const bool bNoDataValueInt64Valid =
isIntegerDT && GDALIsValueExactAs<GInt64>(dfNoDataValue);
const auto nNodataValueInt64 =
bNoDataValueInt64Valid ? static_cast<GInt64>(dfNoDataValue) : 0;
constexpr int nWrkDataTypeSize = static_cast<int>(sizeof(Twork));

// TODO: we should have some generic function to do this.
Expand Down Expand Up @@ -3196,8 +3199,8 @@ static CPLErr GDALResampleChunk_ConvolutionT(
}

auto replaceValIfNodata = [bHasNoData, isIntegerDT, fDstMin, fDstMax,
nNodataValueInt64, dfNoDataValue,
dfReplacementVal](Twork fVal)
bNoDataValueInt64Valid, nNodataValueInt64,
dfNoDataValue, dfReplacementVal](Twork fVal)
{
if (!bHasNoData)
return fVal;
Expand All @@ -3211,7 +3214,8 @@ static CPLErr GDALResampleChunk_ConvolutionT(
fClamped = fDstMax;
if (isIntegerDT)
{
if (nNodataValueInt64 == static_cast<GInt64>(std::round(fClamped)))
if (bNoDataValueInt64Valid &&
nNodataValueInt64 == static_cast<GInt64>(std::round(fClamped)))
{
// Do not use the nodata value
return static_cast<Twork>(dfReplacementVal);
Expand Down

0 comments on commit ef607a3

Please sign in to comment.