diff options
author | Vailin Choi <vchoi@hdfgroup.org> | 2020-03-15 05:43:40 (GMT) |
---|---|---|
committer | Vailin Choi <vchoi@hdfgroup.org> | 2020-03-15 05:43:40 (GMT) |
commit | a34805c8795e0954c098939b184e1ef4707cd8bb (patch) | |
tree | 688e7d8063c6dd6f4594b1fe4784951e7aac95ce | |
parent | 7ae66f2cf819f9b1da0ffd4d00490eb2ea84405a (diff) | |
parent | 19464e2172e5b5d15d4a8ebaee57ef4bc671d897 (diff) | |
download | hdf5-a34805c8795e0954c098939b184e1ef4707cd8bb.zip hdf5-a34805c8795e0954c098939b184e1ef4707cd8bb.tar.gz hdf5-a34805c8795e0954c098939b184e1ef4707cd8bb.tar.bz2 |
Merge pull request #2386 in HDFFV/hdf5 from ~VCHOI/my_third_fork:bugfix/v18_seg_fault_ref_sel_compat to hdf5_1_8
* commit '19464e2172e5b5d15d4a8ebaee57ef4bc671d897':
Verify the decoded version for "all" and "none" selection.
FIx issues when deserializing hyperslab/point selection with version beyond the library's supported version: (1) Verify the decoded version before proceeding further with deserialization (2) Close the dataspace if errors occurred after opening the dataspace
-rw-r--r-- | src/H5R.c | 14 | ||||
-rw-r--r-- | src/H5Sall.c | 14 | ||||
-rw-r--r-- | src/H5Shyper.c | 15 | ||||
-rw-r--r-- | src/H5Snone.c | 14 | ||||
-rw-r--r-- | src/H5Spkg.h | 15 | ||||
-rw-r--r-- | src/H5Spoint.c | 11 |
6 files changed, 72 insertions, 11 deletions
@@ -623,7 +623,8 @@ H5R_get_region(H5F_t *file, hid_t dxpl_id, const void *_ref) const uint8_t *p; /* Pointer to OID to store */ H5HG_t hobjid; /* Heap object ID */ uint8_t *buf = NULL; /* Buffer to store serialized selection in */ - H5S_t *ret_value; + H5S_t *ds = NULL; /* Temporary pointer to dataspace */ + H5S_t *ret_value = NULL; FUNC_ENTER_NOAPI_NOINIT @@ -648,18 +649,25 @@ H5R_get_region(H5F_t *file, hid_t dxpl_id, const void *_ref) H5F_addr_decode(oloc.file, &p, &(oloc.addr)); /* Open and copy the dataset's dataspace */ - if((ret_value = H5S_read(&oloc, dxpl_id)) == NULL) + if((ds = H5S_read(&oloc, dxpl_id)) == NULL) HGOTO_ERROR(H5E_DATASPACE, H5E_NOTFOUND, NULL, "not found") /* Unserialize the selection */ - if(H5S_select_deserialize(ret_value, p) < 0) + if(H5S_select_deserialize(ds, p) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, NULL, "can't deserialize selection") + ret_value = ds; + done: /* Free the buffer allocated in H5HG_read() */ if(buf) H5MM_xfree(buf); + if(ret_value == NULL) { + if(ds && H5S_close(ds) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, NULL, "unable to release dataspace") + } + FUNC_LEAVE_NOAPI(ret_value) } /* end H5R_get_region() */ diff --git a/src/H5Sall.c b/src/H5Sall.c index d57e6c1..86ab0d8 100644 --- a/src/H5Sall.c +++ b/src/H5Sall.c @@ -516,7 +516,7 @@ H5S_all_serialize (const H5S_t *space, uint8_t *buf) /* Store the preamble information */ UINT32ENCODE(buf, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ - UINT32ENCODE(buf, (uint32_t)1); /* Store the version number */ + UINT32ENCODE(buf, (uint32_t)H5S_ALL_VERSION_1); /* Store the version number */ UINT32ENCODE(buf, (uint32_t)0); /* Store the un-used padding */ UINT32ENCODE(buf, (uint32_t)0); /* Store the additional information length */ @@ -544,13 +544,23 @@ H5S_all_serialize (const H5S_t *space, uint8_t *buf) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S_all_deserialize(H5S_t *space, const uint8_t H5_ATTR_UNUSED *buf) +H5S_all_deserialize(H5S_t *space, const uint8_t *buf) { + uint32_t version; /* Decoded version */ + uint8_t *p; /* Temporary pointer to buf */ herr_t ret_value; /* return value */ FUNC_ENTER_NOAPI(FAIL) HDassert(space); + HDassert(buf); + + p = buf + 4; + /* Decode version */ + UINT32DECODE(p, version); + + if(version < H5S_ALL_VERSION_1 || version > H5S_ALL_VERSION_LATEST) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "bad version number for all selection") /* Change to "all" selection */ if((ret_value = H5S_select_all(space, TRUE)) < 0) diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 09d450f..af37b81 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -2120,7 +2120,7 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t *buf) /* Store the preamble information */ UINT32ENCODE(buf, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ - UINT32ENCODE(buf, (uint32_t)1); /* Store the version number */ + UINT32ENCODE(buf, (uint32_t)H5S_HYPER_VERSION_1); /* Store the version number */ UINT32ENCODE(buf, (uint32_t)0); /* Store the un-used padding */ lenp = buf; /* keep the pointer to the length location for later */ buf += 4; /* skip over space for length */ @@ -2265,8 +2265,10 @@ H5S_hyper_deserialize (H5S_t *space, const uint8_t *buf) hsize_t *tstride=NULL; /* temporary hyperslab pointers */ hsize_t *tcount=NULL; /* temporary hyperslab pointers */ hsize_t *tblock=NULL; /* temporary hyperslab pointers */ - unsigned i,j; /* local counting variables */ - herr_t ret_value=FAIL; /* return value */ + unsigned i,j; /* local counting variables */ + uint32_t version; /* decoded version */ + uint8_t *p; /* temporary pointer to buf */ + herr_t ret_value=FAIL; /* return value */ FUNC_ENTER_NOAPI(FAIL) @@ -2274,6 +2276,13 @@ H5S_hyper_deserialize (H5S_t *space, const uint8_t *buf) HDassert(space); HDassert(buf); + p = buf + 4; + UINT32DECODE(p, version); + + if(version < H5S_HYPER_VERSION_1 || version > H5S_HYPER_VERSION_LATEST) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "bad version number for hyperslab selection") + + /* Deserialize slabs to select */ buf+=16; /* Skip over selection header */ UINT32DECODE(buf,rank); /* decode the rank of the point selection */ diff --git a/src/H5Snone.c b/src/H5Snone.c index 1c2af0b..ed20467 100644 --- a/src/H5Snone.c +++ b/src/H5Snone.c @@ -484,7 +484,7 @@ H5S_none_serialize(const H5S_t *space, uint8_t *buf) /* Store the preamble information */ UINT32ENCODE(buf, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ - UINT32ENCODE(buf, (uint32_t)1); /* Store the version number */ + UINT32ENCODE(buf, (uint32_t)H5S_NONE_VERSION_1); /* Store the version number */ UINT32ENCODE(buf, (uint32_t)0); /* Store the un-used padding */ UINT32ENCODE(buf, (uint32_t)0); /* Store the additional information length */ @@ -512,13 +512,23 @@ H5S_none_serialize(const H5S_t *space, uint8_t *buf) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S_none_deserialize(H5S_t *space, const uint8_t H5_ATTR_UNUSED *buf) +H5S_none_deserialize(H5S_t *space, const uint8_t *buf) { + uint8_t *p; /* Temporary pointer to buf */ + uint32_t version; /* Version number */ herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_NOAPI_NOINIT HDassert(space); + HDassert(buf); + + p = buf + 4; + /* Decode version */ + UINT32DECODE(p, version); + + if(version < H5S_NONE_VERSION_1 || version > H5S_NONE_VERSION_LATEST) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "bad version number for none selection") /* Change to "none" selection */ if(H5S_select_none(space) < 0) diff --git a/src/H5Spkg.h b/src/H5Spkg.h index 0597994..3dc7780 100644 --- a/src/H5Spkg.h +++ b/src/H5Spkg.h @@ -32,6 +32,21 @@ #define H5S_VALID_MAX 0x01 #define H5S_VALID_PERM 0x02 +/* Version for hyperslab selection info */ +#define H5S_HYPER_VERSION_1 1 +#define H5S_HYPER_VERSION_LATEST H5S_HYPER_VERSION_1 + +/* Version for point selection info */ +#define H5S_POINT_VERSION_1 1 +#define H5S_POINT_VERSION_LATEST H5S_HYPER_VERSION_1 + +/* Versions for H5S_SEL_NONE selection info */ +#define H5S_NONE_VERSION_1 1 +#define H5S_NONE_VERSION_LATEST H5S_NONE_VERSION_1 + +/* Versions for H5S_SEL_ALL selection info */ +#define H5S_ALL_VERSION_1 1 +#define H5S_ALL_VERSION_LATEST H5S_ALL_VERSION_1 /* Initial version of the dataspace information */ #define H5O_SDSPACE_VERSION_1 1 diff --git a/src/H5Spoint.c b/src/H5Spoint.c index e1dbb4d..59430bb 100644 --- a/src/H5Spoint.c +++ b/src/H5Spoint.c @@ -846,7 +846,7 @@ H5S_point_serialize (const H5S_t *space, uint8_t *buf) /* Store the preamble information */ UINT32ENCODE(buf, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ - UINT32ENCODE(buf, (uint32_t)1); /* Store the version number */ + UINT32ENCODE(buf, (uint32_t)H5S_POINT_VERSION_1); /* Store the version number */ UINT32ENCODE(buf, (uint32_t)0); /* Store the un-used padding */ lenp=buf; /* keep the pointer to the length location for later */ buf+=4; /* skip over space for length */ @@ -907,6 +907,8 @@ H5S_point_deserialize (H5S_t *space, const uint8_t *buf) size_t num_elem=0; /* Number of elements in selection */ hsize_t *coord=NULL, *tcoord; /* Pointer to array of elements */ unsigned i, j; /* local counting variables */ + uint32_t version; /* Decoded version */ + uint8_t *p; /* Temporary pointer to buf */ herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_NOAPI_NOINIT @@ -915,6 +917,13 @@ H5S_point_deserialize (H5S_t *space, const uint8_t *buf) HDassert(space); HDassert(buf); + p = buf + 4; + UINT32DECODE(p, version); + + if(version < H5S_POINT_VERSION_1 || version > H5S_POINT_VERSION_LATEST) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "bad version number for point selection") + + /* Deserialize points to select */ buf += 16; /* Skip over selection header */ UINT32DECODE(buf, rank); /* decode the rank of the point selection */ |