Skip to content

Commit 7179450

Browse files
gshiromaGitHub Enterprise
authored andcommitted
Make sure that DEMInterpolator getBlock() does not exceed DEM raster dimensions (#994)
1 parent f4c69c8 commit 7179450

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

cxx/isce3/geometry/DEMInterpolator.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,18 @@ isce3::error::ErrorCode isce3::geometry::DEMInterpolator::loadDEM(
293293
_deltay = delta_y;
294294

295295
// Get DEMInterpolator width and length
296-
const long width = max_x_idx - min_x_idx;
297-
const long length = max_y_idx - min_y_idx;
296+
long width = max_x_idx - min_x_idx;
297+
long length = max_y_idx - min_y_idx;
298+
299+
// Make sure raster subset is does not extrapolate raster dimensions
300+
if (!flag_dem_file_discontinuity && min_x_idx + width > demRaster.width()) {
301+
width = demRaster.width() - min_x_idx;
302+
max_x_idx = min_x_idx + width;
303+
}
304+
if (!flag_dem_file_discontinuity && min_y_idx + length > demRaster.length()) {
305+
length = demRaster.length() - min_y_idx;
306+
max_y_idx = min_y_idx + length;
307+
}
298308

299309
// If DEM has no valid points, escape
300310
if (width <= 0 || length <= 0) {
@@ -303,16 +313,18 @@ isce3::error::ErrorCode isce3::geometry::DEMInterpolator::loadDEM(
303313
return isce3::error::ErrorCode::OutOfBoundsDem;
304314
}
305315

306-
// Resize DEM array and fill it with NaN values
316+
// Resize DEM array
307317
_dem.resize(length, width);
308-
_dem.fill(std::numeric_limits<float>::quiet_NaN());
309318

310319
if (!flag_dem_file_discontinuity) {
311320
// Read single block from DEM
312321
demRaster.getBlock(_dem.data(), min_x_idx, min_y_idx, width, length);
313322

314323
} else {
315324

325+
// Fill DEM array with NaN values
326+
_dem.fill(std::numeric_limits<float>::quiet_NaN());
327+
316328
// Read DEM in two blocks "unrolling" the western side of the DEM around
317329
// the DEM file discontinuity
318330
const long width_discontinuity_left = demRaster.width() - min_x_idx;

0 commit comments

Comments
 (0)