From 1565241343f00b203ee86810694d42992336b7f4 Mon Sep 17 00:00:00 2001 From: tbeu Date: Sun, 10 Mar 2024 20:21:00 +0100 Subject: [PATCH] Fix bad argument for H5S_get_simple_extent_dims As reported by https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66627 --- src/mat73.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mat73.c b/src/mat73.c index a042d73c..b5333667 100644 --- a/src/mat73.c +++ b/src/mat73.c @@ -623,18 +623,20 @@ Mat_H5ReadFieldNames(matvar_t *matvar, hid_t dset_id, hsize_t *nfields) hsize_t i; hid_t attr_id, space_id; herr_t herr; - int err; + int err, ndims; attr_id = H5Aopen_by_name(dset_id, ".", "MATLAB_fields", H5P_DEFAULT, H5P_DEFAULT); space_id = H5Aget_space(attr_id); - err = H5Sget_simple_extent_dims(space_id, nfields, NULL); - if ( err < 0 ) { + ndims = H5Sget_simple_extent_ndims(space_id); + if ( 0 > ndims || 1 < ndims ) { + *nfields = 0; H5Sclose(space_id); H5Aclose(attr_id); return MATIO_E_GENERIC_READ_ERROR; } else { err = MATIO_E_NO_ERROR; } + (void)H5Sget_simple_extent_dims(space_id, nfields, NULL); if ( *nfields > 0 ) { hid_t field_id; hvl_t *fieldnames_vl = (hvl_t *)calloc((size_t)(*nfields), sizeof(*fieldnames_vl));