Skip to content

Commit

Permalink
Hdffv 11052 (#2315)
Browse files Browse the repository at this point in the history
* Fix for HDFFV-11052: h5debug fails on a corrupted file (h5_nrefs_POC) producing a core dump.
When h5debug closes the corrupted file, the library calls H5F__dest() which performs all the
closing operations for the file "f" (H5F_t *) but just keeping note of errors in "ret_value"
all the way till the end of the routine.  The user-provided corrupted file has an illegal
file size causing failure when reading the image during the closing process.
At the end of this routine it sets f->shared to NULL and then frees "f".
This is done whether there is error or not in "ret_value".
Due to the failure in reading the file earlier, the routine then returns error.
The error return from H5F__dest() causes the file object "f" not being removed from the
ID node table.  When the library finally exits, it will try to close the
file objects in the table.  This causes assert failure when H5F_ID_EXISTS(f) or H5F_NREFS(f).
Fix:
a) H5F_dest(): free the f only when there is no error in "ret_value" at the end of the routine.
b) H5VL__native_file_close(): if f->shared is NULL, free "f"; otherwise, perform closing on "f" as before.
c) h5debug.c main(): track error return from H5Fclose().

* Committing clang-format changes

* Add test and release note info for fix to HDFFV-11052 which is merged via PR#2291.

* Committing clang-format changes

* Add the test file to Cmake.

* Skip test_misc37() for drivers that is not default compatible as it is using a pre-generated file.

* Committing clang-format changes

Co-authored-by: vchoi <vchoi@jelly.ad.hdfgroup.org>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 16, 2022
1 parent 0e76aba commit 6b6bcde
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/tmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6060,15 +6060,23 @@ test_misc36(void)
static void
test_misc37(void)
{
const char *fname;
const char *testfile = H5_get_srcdir_filename(CVE_2020_10812_FILENAME);
hbool_t driver_is_default_compatible;
hid_t fid;
herr_t ret;

/* Output message about test being performed */
MESSAGE(5, ("Fix for HDFFV-11052/CVE-2020-10812"));

fname = H5_get_srcdir_filename(CVE_2020_10812_FILENAME);
fid = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT);
ret = h5_driver_is_default_vfd_compatible(H5P_DEFAULT, &driver_is_default_compatible);
CHECK(ret, FAIL, "h5_driver_is_default_vfd_compatible");

if (!driver_is_default_compatible) {
HDprintf("-- SKIPPED --\n");
return;
}

fid = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid, FAIL, "H5Fopen");

/* This should fail due to the illegal file size.
Expand Down

0 comments on commit 6b6bcde

Please sign in to comment.