From 088c08c125d888c31ee9563144633c20d9f8e524 Mon Sep 17 00:00:00 2001 From: Burlen Loring Date: Tue, 4 May 2021 22:26:47 -0700 Subject: [PATCH] coordinat_util validate bounds_to_extent calculations --- alg/teca_cartesian_mesh_regrid.cxx | 4 +++- alg/teca_cartesian_mesh_source.cxx | 6 ++++-- alg/teca_cartesian_mesh_subset.cxx | 6 ++++-- alg/teca_normalize_coordinates.cxx | 6 ++++-- data/teca_coordinate_util.cxx | 21 +++++++++++++++------ 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/alg/teca_cartesian_mesh_regrid.cxx b/alg/teca_cartesian_mesh_regrid.cxx index 1095560eb..b8f90aa35 100644 --- a/alg/teca_cartesian_mesh_regrid.cxx +++ b/alg/teca_cartesian_mesh_regrid.cxx @@ -372,7 +372,9 @@ std::vector teca_cartesian_mesh_regrid::get_upstream_request( else { if (teca_coordinate_util::bounds_to_extent(request_bounds, - target_x, target_y, target_z, target_extent)) + target_x, target_y, target_z, target_extent) || + teca_coordinate_util::validate_extent(target_x->size(), + target_y->size(), target_z->size(), target_extent, true)) { TECA_ERROR("invalid bounds requested [" << request_bounds[0] << ", " << request_bounds[1] << ", " << request_bounds[2] << ", " diff --git a/alg/teca_cartesian_mesh_source.cxx b/alg/teca_cartesian_mesh_source.cxx index ee4349ec7..2139a9864 100644 --- a/alg/teca_cartesian_mesh_source.cxx +++ b/alg/teca_cartesian_mesh_source.cxx @@ -659,8 +659,10 @@ const_p_teca_dataset teca_cartesian_mesh_source::execute(unsigned int port, { // bounds key was present, convert the bounds to an // an extent that covers them. - if (teca_coordinate_util::bounds_to_extent( - req_bounds, in_x, in_y, in_z, req_extent)) + if (teca_coordinate_util::bounds_to_extent(req_bounds, + in_x, in_y, in_z, req_extent) || + teca_coordinate_util::validate_extent(in_x->size(), + in_y->size(), in_z->size(), req_extent, true)) { TECA_ERROR("invalid bounds requested.") return nullptr; diff --git a/alg/teca_cartesian_mesh_subset.cxx b/alg/teca_cartesian_mesh_subset.cxx index 14559bede..81837966d 100644 --- a/alg/teca_cartesian_mesh_subset.cxx +++ b/alg/teca_cartesian_mesh_subset.cxx @@ -89,8 +89,10 @@ teca_metadata teca_cartesian_mesh_subset::get_output_metadata( } this->extent.resize(6, 0UL); - if (teca_coordinate_util::bounds_to_extent( - this->bounds.data(), x, y, z, this->extent.data())) + if (teca_coordinate_util::bounds_to_extent(this->bounds.data(), + x, y, z, this->extent.data()) || + teca_coordinate_util::validate_extent(x->size(), + y->size(), z->size(), this->extent.data(), true)) { TECA_ERROR("Failed to convert bounds to extent") return teca_metadata(); diff --git a/alg/teca_normalize_coordinates.cxx b/alg/teca_normalize_coordinates.cxx index d8b360825..e8ceac8e3 100644 --- a/alg/teca_normalize_coordinates.cxx +++ b/alg/teca_normalize_coordinates.cxx @@ -729,8 +729,10 @@ std::vector teca_normalize_coordinates::get_upstream_request( unsigned long extent_out[6]; memcpy(extent_out, extent_in, 6*sizeof(unsigned long)); - if (teca_coordinate_util::bounds_to_extent(tfm_bounds, in_x, - in_y, z, extent_out)) + if (teca_coordinate_util::bounds_to_extent(tfm_bounds, + in_x, in_y, z, extent_out) || + teca_coordinate_util::validate_extent(in_x->size(), + in_y->size(), z->size(), extent_out, true)) { TECA_ERROR("invalid bounds requested.") return up_reqs; diff --git a/data/teca_coordinate_util.cxx b/data/teca_coordinate_util.cxx index 0a2965b47..e00b177d1 100644 --- a/data/teca_coordinate_util.cxx +++ b/data/teca_coordinate_util.cxx @@ -140,7 +140,7 @@ int bounds_to_extent(const double *bounds, const teca_metadata &md, teca_metadata coords; if (md.get("coordinates", coords)) { - TECA_ERROR("missing cooridnates") + TECA_ERROR("Metadata issue, missing cooridnates") return -1; } @@ -150,11 +150,20 @@ int bounds_to_extent(const double *bounds, const teca_metadata &md, if (!x || !y || !z) { - TECA_ERROR("empty coordinate axes") + TECA_ERROR("Metadata issue, empty coordinate axes") return -1; } - return bounds_to_extent(bounds, x, y, z, extent); + if (bounds_to_extent(bounds, x, y, z, extent) || + validate_extent(x->size(), y->size(), z->size(), extent, true)) + { + TECA_ERROR("Invalid bounds raequested [" << bounds[0] << ", " + << bounds[1] << ", " << bounds[2] << ", " << bounds[3] << ", " + << bounds[4] << ", " << bounds[5] << "]") + return -1; + } + + return 0; } // ************************************************************************** @@ -400,7 +409,7 @@ int validate_extent(unsigned long nx_max, unsigned long ny_max, unsigned long nz_max, unsigned long *extent, bool verbose) { // validate x - if (extent[1] >= nx_max) + if ((extent[1] >= nx_max) || (extent[1] < extent[0])) { if (verbose) { @@ -412,7 +421,7 @@ int validate_extent(unsigned long nx_max, unsigned long ny_max, } // validate y - if (extent[3] >= ny_max) + if ((extent[3] >= ny_max) || (extent[3] < extent[2])) { if (verbose) { @@ -424,7 +433,7 @@ int validate_extent(unsigned long nx_max, unsigned long ny_max, } // validate z - if (extent[5] >= nz_max) + if ((extent[5] >= nz_max) || (extent[5] < extent[4])) { if (verbose) {