diff options
author | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2015-03-05 21:42:42 (GMT) |
---|---|---|
committer | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2015-03-05 21:42:42 (GMT) |
commit | ca0a4d24b62980263c6b632550028789a587f7a4 (patch) | |
tree | c6f868ea973e2c94946e8e15338adcc973236132 | |
parent | 61dcc807af6288831117100a370b537fd9d6d041 (diff) | |
download | hdf5-ca0a4d24b62980263c6b632550028789a587f7a4.zip hdf5-ca0a4d24b62980263c6b632550028789a587f7a4.tar.gz hdf5-ca0a4d24b62980263c6b632550028789a587f7a4.tar.bz2 |
[svn-r26373] Fix for HDFFV-7959:
H5Rdereference should check for default (HADDR_UNDEF) value and not continue processing and return so that ret value can be checked and handled properly
Tested: jam (gnu)
-rw-r--r-- | src/H5R.c | 13 | ||||
-rw-r--r-- | test/trefer.c | 75 |
2 files changed, 86 insertions, 2 deletions
@@ -411,6 +411,10 @@ done: 13 July 2011 I added the OAPL_ID parameter for the object being referenced. It only supports dataset access property list currently. + + M. Scot Breitenfeld + 3 March 2015 + Added a check for undefined reference pointer. --------------------------------------------------------------------------*/ hid_t H5R_dereference(H5F_t *file, hid_t oapl_id, hid_t dxpl_id, H5R_type_t ref_type, const void *_ref, hbool_t app_ref) @@ -435,8 +439,10 @@ H5R_dereference(H5F_t *file, hid_t oapl_id, hid_t dxpl_id, H5R_type_t ref_type, switch(ref_type) { case H5R_OBJECT: oloc.addr = *(const hobj_ref_t *)_ref; /* Only object references currently supported */ - break; - + if(!H5F_addr_defined(oloc.addr) || oloc.addr == 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Undefined reference pointer") + break; + case H5R_DATASET_REGION: { H5HG_t hobjid; /* Heap object ID */ @@ -448,6 +454,9 @@ H5R_dereference(H5F_t *file, hid_t oapl_id, hid_t dxpl_id, H5R_type_t ref_type, H5F_addr_decode(oloc.file, &p, &(hobjid.addr)); UINT32DECODE(p, hobjid.idx); + if(!H5F_addr_defined(hobjid.addr) || hobjid.addr == 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Undefined reference pointer") + /* Get the dataset region from the heap (allocate inside routine) */ if(NULL == (buf = (uint8_t *)H5HG_read(oloc.file, dxpl_id, &hobjid, NULL, NULL))) HGOTO_ERROR(H5E_REFERENCE, H5E_READERROR, FAIL, "Unable to read dataset region information") diff --git a/test/trefer.c b/test/trefer.c index 9cb7f26..25cc71c 100644 --- a/test/trefer.c +++ b/test/trefer.c @@ -522,6 +522,12 @@ test_reference_region(void) H5O_type_t obj_type; /* Type of object */ int i, j; /* counting variables */ herr_t ret; /* Generic return value */ + haddr_t addr = HADDR_UNDEF; /* test for undefined reference */ + hid_t dset_NA; /* Dataset id for undefined reference */ + hid_t space_NA; /* Dataspace id for undefined reference */ + hsize_t dims_NA[1] = {1}; /* Dims array for undefined reference */ + hdset_reg_ref_t wdata_NA[1], /* Write buffer */ + rdata_NA[1]; /* Read buffer */ /* Output message about test being performed */ MESSAGE(5, ("Testing Dataset Region Reference Functions\n")); @@ -612,6 +618,31 @@ test_reference_region(void) ret = H5Dwrite(dset1, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf); CHECK(ret, FAIL, "H5Dwrite"); + /* + * Store a dataset region reference which will not get written to disk + */ + + /* Create reference to an element in dset1 */ + ret = H5Sselect_elements(sid2, H5S_SELECT_SET, (size_t)1, (const hsize_t *)coord1); + CHECK(ret, FAIL, "H5Sselect_elements"); + ret = H5Rcreate(&wdata_NA[0], fid1, "/Dataset1", H5R_DATASET_REGION, sid2); + CHECK(ret, FAIL, "H5Rcreate"); + + /* Create the dataspace of the region references */ + space_NA = H5Screate_simple(1, dims_NA, NULL); + CHECK(space_NA, FAIL, "H5Screate_simple"); + + /* Create the dataset and write the region references to it */ + dset_NA = H5Dcreate(fid1, "DS_NA", H5T_STD_REF_DSETREG, space_NA, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT); + CHECK(dset_NA, FAIL, "H5Dcreate"); + + /* Close and release resources for undefined region reference tests */ + ret = H5Dclose(dset_NA); + CHECK(ret, FAIL, "H5Dclose"); + ret = H5Sclose(space_NA); + CHECK(ret, FAIL, "H5Sclose"); + /* Close disk dataspace */ ret = H5Sclose(sid1); CHECK(ret, FAIL, "H5Sclose"); @@ -632,6 +663,41 @@ test_reference_region(void) fid1 = H5Fopen(FILE2, H5F_ACC_RDWR, H5P_DEFAULT); CHECK(fid1, FAIL, "H5Fopen"); + /* + * Start the test of an undefined reference + */ + + /* Open the dataset of the undefined references */ + dset_NA = H5Dopen2(fid1, "DS_NA", H5P_DEFAULT); + CHECK(dset_NA, FAIL, "H5Dopen2"); + + /* Read the data */ + ret = H5Dread(dset_NA, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata_NA); + CHECK(ret, FAIL, "H5Dread"); + + /* + * Dereference an undefined reference (should fail) + */ + H5E_BEGIN_TRY { + dset2 = H5Rdereference2(dset_NA, H5P_DEFAULT, H5R_DATASET_REGION, &rdata_NA[0]); + } H5E_END_TRY; + VERIFY(dset2, FAIL, "H5Rdereference2"); + + /* Close and release resources. */ + ret = H5Dclose(dset_NA); + CHECK(ret, FAIL, "H5Dclose"); + + /* This close should fail since H5Rdereference2 never created + * the id of the referenced object. */ + H5E_BEGIN_TRY { + ret = H5Dclose(dset2); + } H5E_END_TRY; + VERIFY(ret, FAIL, "H5Dclose"); + + /* + * End the test of an undefined reference + */ + /* Open the dataset */ dset1 = H5Dopen2(fid1, "/Dataset1", H5P_DEFAULT); CHECK(dset1, FAIL, "H5Dopen2"); @@ -640,6 +706,10 @@ test_reference_region(void) ret = H5Dread(dset1, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf); CHECK(ret, FAIL, "H5Dread"); + /* Try to read an unaddressed dataset */ + dset2 = H5Rdereference2(dset1, dapl_id, H5R_DATASET_REGION, &addr); + VERIFY(dset2, FAIL, "H5Rdereference2 haddr_undef"); + /* Try to open objects */ dset2 = H5Rdereference2(dset1, dapl_id, H5R_DATASET_REGION, &rbuf[0]); CHECK(dset2, FAIL, "H5Rdereference2"); @@ -1070,6 +1140,7 @@ test_reference_obj_deleted(void) hid_t sid1; /* Dataspace ID */ hobj_ref_t oref; /* Object Reference to test */ H5O_type_t obj_type; /* Object type */ + haddr_t addr = HADDR_UNDEF; /* test for undefined reference */ herr_t ret; /* Generic return value */ /* Create file */ @@ -1127,6 +1198,10 @@ test_reference_obj_deleted(void) dataset = H5Dopen2(fid1, "/Dataset2", H5P_DEFAULT); CHECK(ret, FAIL, "H5Dopen2"); + /* Open undefined reference */ + dset2 = H5Rdereference2(dataset, H5P_DEFAULT, H5R_OBJECT, &addr); + VERIFY(dset2, FAIL, "H5Rdereference2"); + /* Read selection from disk */ HDmemset(&oref, 0, sizeof(hobj_ref_t)); ret = H5Dread(dataset, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, &oref); |