From 9026234017ebdc0c556fbc342ead4ebbe14ce7e1 Mon Sep 17 00:00:00 2001 From: Ryan Friedman Date: Mon, 22 Apr 2024 07:50:32 -0600 Subject: [PATCH] Add better overflow protection Signed-off-by: Ryan Friedman --- geospatial/src/Dem.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/geospatial/src/Dem.cc b/geospatial/src/Dem.cc index d692e50f..83b42999 100644 --- a/geospatial/src/Dem.cc +++ b/geospatial/src/Dem.cc @@ -551,6 +551,7 @@ int Dem::LoadData() std::vector buffer; // Convert to uint64_t for multiplication to avoid overflow. // https://github.com/OSGeo/gdal/issues/9713 + static_assert(std::numeric_limits::max() >= std::numeric_limits::max() * std::numeric_limits::max()); buffer.resize(static_cast(destWidth) * static_cast(destHeight)); //! @todo Do not assume users only want to load from the origin of the dataset. // Instead, add a configuration to change where in the dataset to read from. @@ -564,7 +565,7 @@ int Dem::LoadData() // Copy and align 'buffer' into the target vector. The destination vector is // initialized to max() and later converted to the minimum elevation, so all // the points not contained in 'buffer' will be extra padding - this->dataPtr->demData.resize(this->Width() * this->Height(), + this->dataPtr->demData.resize(static_cast(this->Width()) * static_cast(this->Height()), this->dataPtr->bufferVal); for (unsigned int y = 0; y < destHeight; ++y) {