# HG changeset patch # User Markus Mützel # Date 1613922311 -3600 # Sun Feb 21 16:45:11 2021 +0100 # Branch stable # Node ID 26039aa0d2c424e853a1e0ec027389a54074837a # Parent 2aa23c8f3ef3468c6d23efa114ee0acc4a22169d ls-hdf5.cc: Avoid throwing inside HDF5 function (bug #60081). * ls-hdf5.cc (hdf5_read_next_data_internal): Don't throw an error inside a function that is called by the HDF5 library. Catch the exception and let the HDF5 library recover from any error cleanly instead. diff -r 2aa23c8f3ef3 -r 26039aa0d2c4 libinterp/corefcn/ls-hdf5.cc --- a/libinterp/corefcn/ls-hdf5.cc Mon Feb 15 18:09:01 2021 +0100 +++ b/libinterp/corefcn/ls-hdf5.cc Sun Feb 21 16:45:11 2021 +0100 @@ -649,6 +649,8 @@ // It returns 1 on success (in which case H5Giterate stops and returns), // -1 on error, and 0 to tell H5Giterate to continue on to the next item // (e.g., if NAME was a data type we don't recognize). +// +// This function must not throw an exception. static herr_t hdf5_read_next_data_internal (hid_t group_id, const char *name, void *dv) @@ -734,8 +736,8 @@ hid_t st_id = H5Tcopy (H5T_C_S1); H5Tset_size (st_id, slen); - if (H5Dread (data_id, st_id, octave_H5S_ALL, octave_H5S_ALL, octave_H5P_DEFAULT, - typ) < 0) + if (H5Dread (data_id, st_id, octave_H5S_ALL, octave_H5S_ALL, + octave_H5P_DEFAULT, typ) < 0) goto done; H5Tclose (st_id); @@ -749,7 +751,14 @@ { d->tc = type_info.lookup_type (typ); - retval = (d->tc.load_hdf5 (subgroup_id, "value") ? 1 : -1); + try + { + retval = (d->tc.load_hdf5 (subgroup_id, "value") ? 1 : -1); + } + catch (const octave::execution_exception& ee) + { + retval = -1; + } } // check for OCTAVE_GLOBAL attribute: @@ -777,7 +786,14 @@ H5Gclose (subgroup_id); - retval = (d->tc.load_hdf5 (group_id, name) ? 1 : -1); + try + { + retval = (d->tc.load_hdf5 (group_id, name) ? 1 : -1); + } + catch (const octave::execution_exception& ee) + { + retval = -1; + } } } @@ -967,7 +983,14 @@ // check for OCTAVE_GLOBAL attribute: d->global = hdf5_check_attr (data_id, "OCTAVE_GLOBAL"); - retval = (d->tc.load_hdf5 (group_id, name) ? 1 : -1); + try + { + retval = (d->tc.load_hdf5 (group_id, name) ? 1 : -1); + } + catch (const octave::execution_exception& ee) + { + retval = -1; + } H5Tclose (type_id); H5Dclose (data_id);