From 0508309b7afb904611bdd210efe36e36de7acd5b Mon Sep 17 00:00:00 2001 From: Anthony Papetti Date: Fri, 18 Oct 2024 12:33:39 -0400 Subject: [PATCH 1/5] Fixed segmentation faults by giving H5DOpen and H5GOpen error checking --- api/bag_dataset.cpp | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/api/bag_dataset.cpp b/api/bag_dataset.cpp index ab04c9276b..91372b342c 100644 --- a/api/bag_dataset.cpp +++ b/api/bag_dataset.cpp @@ -1055,6 +1055,26 @@ std::tuple Dataset::gridToGeo( return {x, y}; } +hid_t DopenProtector2(hid_t loc_id, const char *name, hid_t dapl_id) { + hid_t id = -1; + try { + id = H5Dopen2(loc_id, name, dapl_id); + } catch (std::exception& e) { + id = -1; + } + return id; +} + +hid_t GopenProtector2(hid_t loc_id, const char *name, hid_t dapl_id) { + hid_t id = -1; + try { + id = H5Dopen2(loc_id, name, dapl_id); + } catch (std::exception& e) { + id = -1; + } + return id; +} + //! Read an existing BAG. /*! \param fileName @@ -1088,8 +1108,7 @@ void Dataset::readDataset( const std::string internalPath = Layer::getInternalPath(layerType); if (internalPath.empty()) continue; - - const hid_t id = H5Dopen2(bagGroup.getLocId(), internalPath.c_str(), + hid_t id = DopenProtector2(bagGroup.getLocId(), internalPath.c_str(), H5P_DEFAULT); if (id < 0) continue; @@ -1105,7 +1124,7 @@ void Dataset::readDataset( // If the BAG is version 1.5+ ... if (bagVersion >= 1'005'000) { - hid_t id = H5Dopen2(bagGroup.getLocId(), NODE_GROUP_PATH, H5P_DEFAULT); + hid_t id = DopenProtector2(bagGroup.getLocId(), NODE_GROUP_PATH, H5P_DEFAULT); if (id >= 0) { H5Dclose(id); @@ -1120,8 +1139,7 @@ void Dataset::readDataset( NODE); this->addLayer(InterleavedLegacyLayer::open(*this, *layerDesc)); } - - id = H5Dopen2(bagGroup.getLocId(), ELEVATION_SOLUTION_GROUP_PATH, + id = DopenProtector2(bagGroup.getLocId(), ELEVATION_SOLUTION_GROUP_PATH, H5P_DEFAULT); if (id >= 0) { @@ -1146,7 +1164,7 @@ void Dataset::readDataset( } // Read optional VR - hid_t id = H5Dopen2(bagGroup.getLocId(), VR_TRACKING_LIST_PATH, H5P_DEFAULT); + hid_t id = DopenProtector2(bagGroup.getLocId(), VR_TRACKING_LIST_PATH, H5P_DEFAULT); if (id >= 0) { H5Dclose(id); @@ -1164,7 +1182,7 @@ void Dataset::readDataset( } // optional VRNodeLayer - id = H5Dopen2(bagGroup.getLocId(), VR_NODE_PATH, H5P_DEFAULT); + id = DopenProtector2(bagGroup.getLocId(), VR_NODE_PATH, H5P_DEFAULT); if (id >= 0) { H5Dclose(id); @@ -1177,7 +1195,7 @@ void Dataset::readDataset( m_pTrackingList = std::unique_ptr(new TrackingList{*this}); // Read optional Surface Corrections - id = H5Dopen2(bagGroup.getLocId(), VERT_DATUM_CORR_PATH, H5P_DEFAULT); + id = DopenProtector2(bagGroup.getLocId(), VERT_DATUM_CORR_PATH, H5P_DEFAULT); if (id >= 0) { H5Dclose(id); @@ -1190,7 +1208,7 @@ void Dataset::readDataset( if (bagVersion >= 2'000'000) { // Add all existing GeorefMetadataLayers - id = H5Gopen2(bagGroup.getLocId(), GEOREF_METADATA_PATH, H5P_DEFAULT); + id = GopenProtector2(bagGroup.getLocId(), GEOREF_METADATA_PATH, H5P_DEFAULT); if (id >= 0) { H5Gclose(id); From d9535fe1e41060842988169382abd7dee181c9ab Mon Sep 17 00:00:00 2001 From: Anthony Papetti Date: Thu, 14 Nov 2024 13:30:52 -0500 Subject: [PATCH 2/5] Fixed syntax in bag_dataset --- api/bag_dataset.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/bag_dataset.cpp b/api/bag_dataset.cpp index de90b69ced..33ef78083e 100644 --- a/api/bag_dataset.cpp +++ b/api/bag_dataset.cpp @@ -1075,7 +1075,8 @@ hid_t GopenProtector2(hid_t loc_id, const char *name, hid_t dapl_id) { id = -1; } return id; - +} + void handleAbrt(int signum) { std::cerr << "\nUnrecoverable HDF5 Error \n"; exit(signum); From a48c7a3115aba540a309ffd7f91422f1eead2c61 Mon Sep 17 00:00:00 2001 From: Anthony Papetti Date: Fri, 21 Feb 2025 12:46:32 -0500 Subject: [PATCH 3/5] Fixed open protector method --- api/bag_dataset.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/bag_dataset.cpp b/api/bag_dataset.cpp index 33ef78083e..c3d91f9d9e 100644 --- a/api/bag_dataset.cpp +++ b/api/bag_dataset.cpp @@ -1070,7 +1070,7 @@ hid_t DopenProtector2(hid_t loc_id, const char *name, hid_t dapl_id) { hid_t GopenProtector2(hid_t loc_id, const char *name, hid_t dapl_id) { hid_t id = -1; try { - id = H5Dopen2(loc_id, name, dapl_id); + id = H5Gopen2(loc_id, name, dapl_id); } catch (std::exception& e) { id = -1; } From 77bba217dbd05ecb02f551f62d94ece20baf7f95 Mon Sep 17 00:00:00 2001 From: Anthony Papetti Date: Mon, 24 Feb 2025 15:31:38 -0500 Subject: [PATCH 4/5] Printed unused exception messages --- api/bag_dataset.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/bag_dataset.cpp b/api/bag_dataset.cpp index c3d91f9d9e..b6ff79278b 100644 --- a/api/bag_dataset.cpp +++ b/api/bag_dataset.cpp @@ -1062,6 +1062,7 @@ hid_t DopenProtector2(hid_t loc_id, const char *name, hid_t dapl_id) { try { id = H5Dopen2(loc_id, name, dapl_id); } catch (std::exception& e) { + std::stderr << e.what(); id = -1; } return id; @@ -1072,6 +1073,7 @@ hid_t GopenProtector2(hid_t loc_id, const char *name, hid_t dapl_id) { try { id = H5Gopen2(loc_id, name, dapl_id); } catch (std::exception& e) { + std::stderr << e.what(); id = -1; } return id; From cf050403c4a267a1e67ceab16e190f44c1e20b9e Mon Sep 17 00:00:00 2001 From: Anthony Papetti Date: Mon, 24 Feb 2025 15:48:42 -0500 Subject: [PATCH 5/5] Changed stderr to cerr --- api/bag_dataset.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/bag_dataset.cpp b/api/bag_dataset.cpp index b6ff79278b..e308d5861b 100644 --- a/api/bag_dataset.cpp +++ b/api/bag_dataset.cpp @@ -1062,7 +1062,7 @@ hid_t DopenProtector2(hid_t loc_id, const char *name, hid_t dapl_id) { try { id = H5Dopen2(loc_id, name, dapl_id); } catch (std::exception& e) { - std::stderr << e.what(); + std::cerr << e.what(); id = -1; } return id; @@ -1073,7 +1073,7 @@ hid_t GopenProtector2(hid_t loc_id, const char *name, hid_t dapl_id) { try { id = H5Gopen2(loc_id, name, dapl_id); } catch (std::exception& e) { - std::stderr << e.what(); + std::cerr << e.what(); id = -1; } return id;