From 9f0e6df37267d69e65816a2d0ee738b7f787c349 Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Thu, 14 Mar 2024 16:50:37 -0500 Subject: [PATCH 1/7] Fix error when overwriting an indirectly nested vlen. --- src/H5Tconv.c | 69 ++++++++++++++++++++++-- test/dsets.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+), 4 deletions(-) diff --git a/src/H5Tconv.c b/src/H5Tconv.c index 72debe8d200..a4cf23d9a10 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -3058,6 +3058,67 @@ H5T__conv_enum_numeric(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t ne FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__conv_enum_numeric() */ + +/*------------------------------------------------------------------------- + * Function: H5T__conv_vlen_nested_free + * + * Purpose: Recursively locates and frees any nested VLEN components of + * complex data types (including COMPOUND). + * + * Return: Non-negative on success/Negative on failure. + * + *------------------------------------------------------------------------- + */ +static herr_t +H5T__conv_vlen_nested_free(uint8_t *buf, H5T_t *dt) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + switch (dt->shared->type) { + case H5T_VLEN: + /* Pointer buf refers to VLEN data; free it (always reset tmp) */ + if ((*(dt->shared->u.vlen.cls->del))(dt->shared->u.vlen.file, buf) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't free nested vlen"); + break; + + case H5T_COMPOUND: + /* Pointer buf refers to COMPOUND data; recurse for each member. */ + for (unsigned i = 0; i < dt->shared->u.compnd.nmembs; ++i) + if(H5T__conv_vlen_nested_free(buf + dt->shared->u.compnd.memb[i].offset, dt->shared->u.compnd.memb[i].type) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't free compound member"); + break; + + case H5T_ARRAY: + /* Pointer buf refers to ARRAY data; recurse for each element. */ + for (unsigned i = 0; i < dt->shared->u.array.nelem; ++i) + if(H5T__conv_vlen_nested_free(buf + i * dt->shared->parent->shared->size, dt->shared->parent) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't free array data"); + break; + + case H5T_INTEGER: + case H5T_FLOAT: + case H5T_TIME: + case H5T_STRING: + case H5T_BITFIELD: + case H5T_OPAQUE: + case H5T_REFERENCE: + case H5T_ENUM: + /* These types cannot contain vl data */ + break; + + case H5T_NO_CLASS: + case H5T_NCLASSES: + default: + HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "invalid datatype class"); + } + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5T__conv_vlen_nested_free() */ + + /*------------------------------------------------------------------------- * Function: H5T__conv_vlen * @@ -3396,10 +3457,10 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, si tmp = (uint8_t *)tmp_buf + seq_len * dst_base_size; for (u = seq_len; u < bg_seq_len; u++, tmp += dst_base_size) { - /* Delete sequence in destination location */ - if ((*(dst->shared->u.vlen.cls->del))(dst->shared->u.vlen.file, tmp) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, - "unable to remove heap object"); + /* Recursively free destination data */ + if (H5T__conv_vlen_nested_free(tmp, dst->shared->parent) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, + "unable to remove heap object"); } /* end for */ } /* end if */ } /* end if */ diff --git a/test/dsets.c b/test/dsets.c index aba1f1e3996..2ec0c455559 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -15395,6 +15395,146 @@ test_0sized_dset_metadata_alloc(hid_t fapl_id) return FAIL; } /* end test_0sized_dset_metadata_alloc() */ +/*------------------------------------------------------------------------- + * Function: test_downsize_vlen_scalar_dataset + * + * Purpose: Tests H5Dwrite on a scalar dataset containing a VLEN array + * of { double, C-string }. This causes special code to free + * the nested VLEN (in this case, C-string) allocations. + * + * Return: Success: 0 + * Failure: -1 + * + *------------------------------------------------------------------------- + */ +#define VLEN_DS_NAME "test_downsize_vlen_scalar_dataset" +#define VLEN_DS_DIM 100 +#define VLEN_DS_STRLEN 20 +#define VLEN_DS_STRING "vlen test string" +#define VLEN_DS_VALUE 0.12345678901234567890 +#define VLEN_DS_ARRAY_DIM1 3 +#define VLEN_DS_ARRAY_DIM2 5 + +typedef struct { + double value; + char * string[VLEN_DS_ARRAY_DIM1][VLEN_DS_ARRAY_DIM2]; +} vlen_ds_compound_file_t; + +typedef struct { + int padding1; + double value; + int padding2; + char * string[VLEN_DS_ARRAY_DIM1][VLEN_DS_ARRAY_DIM2]; + int padding3; +} vlen_ds_compound_memory_t; + +static herr_t +test_downsize_vlen_scalar_dataset(hid_t file) +{ + hid_t scalar_sid = -1; /* Scalar dataspace ID */ + hid_t string_tid = -1; /* VARIABLE string datatype ID */ + hid_t string_array_tid = -1; /* VARIABLE string array datatype ID */ + hid_t compound_file_tid = -1; /* COMPOUND datatype ID */ + hid_t compound_memory_tid = -1; /* COMPOUND datatype ID */ + hid_t vlen_compound_file_tid = -1; /* VARIABLE COMPOUND datatype ID */ + hid_t vlen_compound_memory_tid = -1; /* VARIABLE COMPOUND datatype ID */ + hid_t scalar_did = -1; /* SCALAR dataset ID */ + hvl_t vlen_compound_data; /* Top-level VLEN data */ + vlen_ds_compound_memory_t compound_data[VLEN_DS_DIM]; /* Contents of VLEN data */ + char common_string[VLEN_DS_STRLEN]; /* Common string contents */ + hsize_t array_dims[2] = {VLEN_DS_ARRAY_DIM1, VLEN_DS_ARRAY_DIM2}; + int i, dim1, dim2; /* Local index variables */ + + TESTING("H5Dwrite() on down-sized VLEN contents"); + + /* Create scalar dataspace */ + if((scalar_sid = H5Screate(H5S_SCALAR)) < 0) + TEST_ERROR; + + /* Create datatype VLEN{COMPOUND{"value":H5T_NATIVE_DOUBLE, "string":H5T_C_S1|H5T_VARIABLE}} */ + /* Note: the memory and file structures must be different to invoke the bug @ H5Tconv.c:3323 */ + if((string_tid = H5Tcopy(H5T_C_S1)) < 0) + TEST_ERROR; + if(H5Tset_size(string_tid, H5T_VARIABLE) < 0) + TEST_ERROR; + + if((string_array_tid = H5Tarray_create(string_tid, 2, array_dims)) < 0) + TEST_ERROR; + + if((compound_file_tid = H5Tcreate(H5T_COMPOUND, sizeof(vlen_ds_compound_file_t))) < 0) + TEST_ERROR; + if(H5Tinsert(compound_file_tid, "value", HOFFSET(vlen_ds_compound_file_t, value), H5T_NATIVE_DOUBLE) < 0) + TEST_ERROR; + if(H5Tinsert(compound_file_tid, "string", HOFFSET(vlen_ds_compound_file_t, string), string_array_tid) < 0) + TEST_ERROR; + if((vlen_compound_file_tid = H5Tvlen_create(compound_file_tid)) < 0) + TEST_ERROR; + + if((compound_memory_tid = H5Tcreate(H5T_COMPOUND, sizeof(vlen_ds_compound_memory_t))) < 0) + TEST_ERROR; + if(H5Tinsert(compound_memory_tid, "value", HOFFSET(vlen_ds_compound_memory_t, value), H5T_NATIVE_DOUBLE) < 0) + TEST_ERROR; + if(H5Tinsert(compound_memory_tid, "string", HOFFSET(vlen_ds_compound_memory_t, string), string_array_tid) < 0) + TEST_ERROR; + if((vlen_compound_memory_tid = H5Tvlen_create(compound_memory_tid)) < 0) + TEST_ERROR; + + /* Create the scalar dataset of this data type */ + if((scalar_did = H5Dcreate(file, VLEN_DS_NAME, vlen_compound_file_tid, scalar_sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; + + /* Setup the variable-length data. Note that if the double "value" field is set to 0.0, the bug will NOT */ + /* occur because this is the data at offset zero of the element, and it then looks like a NULL VLEN data */ + strcpy(common_string, VLEN_DS_STRING); + + for(i=0; i0; --i) { + vlen_compound_data.len = i; + vlen_compound_data.p = compound_data; + if (H5Dwrite(scalar_did, vlen_compound_memory_tid, scalar_sid, scalar_sid, H5P_DEFAULT, &vlen_compound_data) < 0) + TEST_ERROR; + } + + /* Close everything */ + if(H5Sclose(scalar_sid) < 0) TEST_ERROR; + if(H5Tclose(string_tid) < 0) TEST_ERROR; + if(H5Tclose(string_array_tid) < 0) TEST_ERROR; + if(H5Tclose(compound_file_tid) < 0) TEST_ERROR; + if(H5Tclose(vlen_compound_file_tid) < 0) TEST_ERROR; + if(H5Tclose(compound_memory_tid) < 0) TEST_ERROR; + if(H5Tclose(vlen_compound_memory_tid) < 0) TEST_ERROR; + if(H5Dclose(scalar_did) < 0) TEST_ERROR; + + PASSED(); + return 0; + +error: + H5E_BEGIN_TRY { + H5Sclose(scalar_sid); + H5Tclose(string_tid); + H5Tclose(string_array_tid); + H5Tclose(compound_file_tid); + H5Tclose(vlen_compound_file_tid); + H5Tclose(compound_memory_tid); + H5Tclose(vlen_compound_memory_tid); + H5Dclose(scalar_did); + } H5E_END_TRY; + return -1; +} /* end test_downsize_vlen_scalar_dataset() */ + /*------------------------------------------------------------------------- * Function: main * @@ -15636,6 +15776,8 @@ main(void) nerrors += (test_farray_hdr_fd(envval, my_fapl) < 0 ? 1 : 0); nerrors += (test_bt2_hdr_fd(envval, my_fapl) < 0 ? 1 : 0); + nerrors += (test_downsize_vlen_scalar_dataset(file) < 0 ? 1 : 0); + if (H5Fclose(file) < 0) goto error; } /* end for new_format */ From d2d2357a470fc1ad011744dae38d404d40fef5ab Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 14 Mar 2024 21:53:22 +0000 Subject: [PATCH 2/7] Committing clang-format changes --- src/H5Tconv.c | 14 +++--- test/dsets.c | 135 ++++++++++++++++++++++++++++---------------------- 2 files changed, 84 insertions(+), 65 deletions(-) diff --git a/src/H5Tconv.c b/src/H5Tconv.c index a4cf23d9a10..4219322536c 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -3058,7 +3058,6 @@ H5T__conv_enum_numeric(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t ne FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__conv_enum_numeric() */ - /*------------------------------------------------------------------------- * Function: H5T__conv_vlen_nested_free * @@ -3072,7 +3071,7 @@ H5T__conv_enum_numeric(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t ne static herr_t H5T__conv_vlen_nested_free(uint8_t *buf, H5T_t *dt) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -3086,14 +3085,16 @@ H5T__conv_vlen_nested_free(uint8_t *buf, H5T_t *dt) case H5T_COMPOUND: /* Pointer buf refers to COMPOUND data; recurse for each member. */ for (unsigned i = 0; i < dt->shared->u.compnd.nmembs; ++i) - if(H5T__conv_vlen_nested_free(buf + dt->shared->u.compnd.memb[i].offset, dt->shared->u.compnd.memb[i].type) < 0) + if (H5T__conv_vlen_nested_free(buf + dt->shared->u.compnd.memb[i].offset, + dt->shared->u.compnd.memb[i].type) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't free compound member"); break; case H5T_ARRAY: /* Pointer buf refers to ARRAY data; recurse for each element. */ for (unsigned i = 0; i < dt->shared->u.array.nelem; ++i) - if(H5T__conv_vlen_nested_free(buf + i * dt->shared->parent->shared->size, dt->shared->parent) < 0) + if (H5T__conv_vlen_nested_free(buf + i * dt->shared->parent->shared->size, + dt->shared->parent) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't free array data"); break; @@ -3118,7 +3119,6 @@ H5T__conv_vlen_nested_free(uint8_t *buf, H5T_t *dt) FUNC_LEAVE_NOAPI(ret_value) } /* H5T__conv_vlen_nested_free() */ - /*------------------------------------------------------------------------- * Function: H5T__conv_vlen * @@ -3459,8 +3459,8 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, si for (u = seq_len; u < bg_seq_len; u++, tmp += dst_base_size) { /* Recursively free destination data */ if (H5T__conv_vlen_nested_free(tmp, dst->shared->parent) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, - "unable to remove heap object"); + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, + "unable to remove heap object"); } /* end for */ } /* end if */ } /* end if */ diff --git a/test/dsets.c b/test/dsets.c index 2ec0c455559..2d6d08128cb 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -15407,90 +15407,96 @@ test_0sized_dset_metadata_alloc(hid_t fapl_id) * *------------------------------------------------------------------------- */ -#define VLEN_DS_NAME "test_downsize_vlen_scalar_dataset" -#define VLEN_DS_DIM 100 -#define VLEN_DS_STRLEN 20 -#define VLEN_DS_STRING "vlen test string" -#define VLEN_DS_VALUE 0.12345678901234567890 -#define VLEN_DS_ARRAY_DIM1 3 -#define VLEN_DS_ARRAY_DIM2 5 +#define VLEN_DS_NAME "test_downsize_vlen_scalar_dataset" +#define VLEN_DS_DIM 100 +#define VLEN_DS_STRLEN 20 +#define VLEN_DS_STRING "vlen test string" +#define VLEN_DS_VALUE 0.12345678901234567890 +#define VLEN_DS_ARRAY_DIM1 3 +#define VLEN_DS_ARRAY_DIM2 5 typedef struct { double value; - char * string[VLEN_DS_ARRAY_DIM1][VLEN_DS_ARRAY_DIM2]; + char *string[VLEN_DS_ARRAY_DIM1][VLEN_DS_ARRAY_DIM2]; } vlen_ds_compound_file_t; typedef struct { - int padding1; + int padding1; double value; - int padding2; - char * string[VLEN_DS_ARRAY_DIM1][VLEN_DS_ARRAY_DIM2]; - int padding3; + int padding2; + char *string[VLEN_DS_ARRAY_DIM1][VLEN_DS_ARRAY_DIM2]; + int padding3; } vlen_ds_compound_memory_t; static herr_t test_downsize_vlen_scalar_dataset(hid_t file) { - hid_t scalar_sid = -1; /* Scalar dataspace ID */ - hid_t string_tid = -1; /* VARIABLE string datatype ID */ - hid_t string_array_tid = -1; /* VARIABLE string array datatype ID */ - hid_t compound_file_tid = -1; /* COMPOUND datatype ID */ - hid_t compound_memory_tid = -1; /* COMPOUND datatype ID */ - hid_t vlen_compound_file_tid = -1; /* VARIABLE COMPOUND datatype ID */ - hid_t vlen_compound_memory_tid = -1; /* VARIABLE COMPOUND datatype ID */ - hid_t scalar_did = -1; /* SCALAR dataset ID */ - hvl_t vlen_compound_data; /* Top-level VLEN data */ - vlen_ds_compound_memory_t compound_data[VLEN_DS_DIM]; /* Contents of VLEN data */ - char common_string[VLEN_DS_STRLEN]; /* Common string contents */ - hsize_t array_dims[2] = {VLEN_DS_ARRAY_DIM1, VLEN_DS_ARRAY_DIM2}; - int i, dim1, dim2; /* Local index variables */ + hid_t scalar_sid = -1; /* Scalar dataspace ID */ + hid_t string_tid = -1; /* VARIABLE string datatype ID */ + hid_t string_array_tid = -1; /* VARIABLE string array datatype ID */ + hid_t compound_file_tid = -1; /* COMPOUND datatype ID */ + hid_t compound_memory_tid = -1; /* COMPOUND datatype ID */ + hid_t vlen_compound_file_tid = -1; /* VARIABLE COMPOUND datatype ID */ + hid_t vlen_compound_memory_tid = -1; /* VARIABLE COMPOUND datatype ID */ + hid_t scalar_did = -1; /* SCALAR dataset ID */ + hvl_t vlen_compound_data; /* Top-level VLEN data */ + vlen_ds_compound_memory_t compound_data[VLEN_DS_DIM]; /* Contents of VLEN data */ + char common_string[VLEN_DS_STRLEN]; /* Common string contents */ + hsize_t array_dims[2] = {VLEN_DS_ARRAY_DIM1, VLEN_DS_ARRAY_DIM2}; + int i, dim1, dim2; /* Local index variables */ TESTING("H5Dwrite() on down-sized VLEN contents"); /* Create scalar dataspace */ - if((scalar_sid = H5Screate(H5S_SCALAR)) < 0) + if ((scalar_sid = H5Screate(H5S_SCALAR)) < 0) TEST_ERROR; /* Create datatype VLEN{COMPOUND{"value":H5T_NATIVE_DOUBLE, "string":H5T_C_S1|H5T_VARIABLE}} */ /* Note: the memory and file structures must be different to invoke the bug @ H5Tconv.c:3323 */ - if((string_tid = H5Tcopy(H5T_C_S1)) < 0) + if ((string_tid = H5Tcopy(H5T_C_S1)) < 0) TEST_ERROR; - if(H5Tset_size(string_tid, H5T_VARIABLE) < 0) + if (H5Tset_size(string_tid, H5T_VARIABLE) < 0) TEST_ERROR; - if((string_array_tid = H5Tarray_create(string_tid, 2, array_dims)) < 0) + if ((string_array_tid = H5Tarray_create(string_tid, 2, array_dims)) < 0) TEST_ERROR; - if((compound_file_tid = H5Tcreate(H5T_COMPOUND, sizeof(vlen_ds_compound_file_t))) < 0) + if ((compound_file_tid = H5Tcreate(H5T_COMPOUND, sizeof(vlen_ds_compound_file_t))) < 0) TEST_ERROR; - if(H5Tinsert(compound_file_tid, "value", HOFFSET(vlen_ds_compound_file_t, value), H5T_NATIVE_DOUBLE) < 0) + if (H5Tinsert(compound_file_tid, "value", HOFFSET(vlen_ds_compound_file_t, value), H5T_NATIVE_DOUBLE) < 0) TEST_ERROR; - if(H5Tinsert(compound_file_tid, "string", HOFFSET(vlen_ds_compound_file_t, string), string_array_tid) < 0) + if (H5Tinsert(compound_file_tid, "string", HOFFSET(vlen_ds_compound_file_t, string), string_array_tid) < + 0) TEST_ERROR; - if((vlen_compound_file_tid = H5Tvlen_create(compound_file_tid)) < 0) + if ((vlen_compound_file_tid = H5Tvlen_create(compound_file_tid)) < 0) TEST_ERROR; - if((compound_memory_tid = H5Tcreate(H5T_COMPOUND, sizeof(vlen_ds_compound_memory_t))) < 0) + if ((compound_memory_tid = H5Tcreate(H5T_COMPOUND, sizeof(vlen_ds_compound_memory_t))) < 0) TEST_ERROR; - if(H5Tinsert(compound_memory_tid, "value", HOFFSET(vlen_ds_compound_memory_t, value), H5T_NATIVE_DOUBLE) < 0) + if (H5Tinsert(compound_memory_tid, "value", HOFFSET(vlen_ds_compound_memory_t, value), + H5T_NATIVE_DOUBLE) < 0) TEST_ERROR; - if(H5Tinsert(compound_memory_tid, "string", HOFFSET(vlen_ds_compound_memory_t, string), string_array_tid) < 0) + if (H5Tinsert(compound_memory_tid, "string", HOFFSET(vlen_ds_compound_memory_t, string), + string_array_tid) < 0) TEST_ERROR; - if((vlen_compound_memory_tid = H5Tvlen_create(compound_memory_tid)) < 0) + if ((vlen_compound_memory_tid = H5Tvlen_create(compound_memory_tid)) < 0) TEST_ERROR; /* Create the scalar dataset of this data type */ - if((scalar_did = H5Dcreate(file, VLEN_DS_NAME, vlen_compound_file_tid, scalar_sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + if ((scalar_did = H5Dcreate(file, VLEN_DS_NAME, vlen_compound_file_tid, scalar_sid, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; - /* Setup the variable-length data. Note that if the double "value" field is set to 0.0, the bug will NOT */ - /* occur because this is the data at offset zero of the element, and it then looks like a NULL VLEN data */ + /* Setup the variable-length data. Note that if the double "value" field is set to 0.0, the bug will NOT + */ + /* occur because this is the data at offset zero of the element, and it then looks like a NULL VLEN data + */ strcpy(common_string, VLEN_DS_STRING); - for(i=0; i0; --i) { + /* Starting with the maximum size, progressively over-write the content of the dataset with smaller + * arrays. */ + /* Note: the bug in v1.8.14 is tripped on the second iteration, when 100 elements are over-written + * with 99. */ + for (i = VLEN_DS_DIM; i > 0; --i) { vlen_compound_data.len = i; - vlen_compound_data.p = compound_data; - if (H5Dwrite(scalar_did, vlen_compound_memory_tid, scalar_sid, scalar_sid, H5P_DEFAULT, &vlen_compound_data) < 0) + vlen_compound_data.p = compound_data; + if (H5Dwrite(scalar_did, vlen_compound_memory_tid, scalar_sid, scalar_sid, H5P_DEFAULT, + &vlen_compound_data) < 0) TEST_ERROR; } /* Close everything */ - if(H5Sclose(scalar_sid) < 0) TEST_ERROR; - if(H5Tclose(string_tid) < 0) TEST_ERROR; - if(H5Tclose(string_array_tid) < 0) TEST_ERROR; - if(H5Tclose(compound_file_tid) < 0) TEST_ERROR; - if(H5Tclose(vlen_compound_file_tid) < 0) TEST_ERROR; - if(H5Tclose(compound_memory_tid) < 0) TEST_ERROR; - if(H5Tclose(vlen_compound_memory_tid) < 0) TEST_ERROR; - if(H5Dclose(scalar_did) < 0) TEST_ERROR; + if (H5Sclose(scalar_sid) < 0) + TEST_ERROR; + if (H5Tclose(string_tid) < 0) + TEST_ERROR; + if (H5Tclose(string_array_tid) < 0) + TEST_ERROR; + if (H5Tclose(compound_file_tid) < 0) + TEST_ERROR; + if (H5Tclose(vlen_compound_file_tid) < 0) + TEST_ERROR; + if (H5Tclose(compound_memory_tid) < 0) + TEST_ERROR; + if (H5Tclose(vlen_compound_memory_tid) < 0) + TEST_ERROR; + if (H5Dclose(scalar_did) < 0) + TEST_ERROR; PASSED(); return 0; error: - H5E_BEGIN_TRY { + H5E_BEGIN_TRY + { H5Sclose(scalar_sid); H5Tclose(string_tid); H5Tclose(string_array_tid); @@ -15531,7 +15549,8 @@ test_downsize_vlen_scalar_dataset(hid_t file) H5Tclose(compound_memory_tid); H5Tclose(vlen_compound_memory_tid); H5Dclose(scalar_did); - } H5E_END_TRY; + } + H5E_END_TRY; return -1; } /* end test_downsize_vlen_scalar_dataset() */ From eade41874d5c6d7ac64862b27c6ce7e3e84a10be Mon Sep 17 00:00:00 2001 From: Dana Robinson <43805+derobins@users.noreply.github.com> Date: Fri, 15 Mar 2024 00:17:06 -0700 Subject: [PATCH 3/7] H5Dcreate --> H5Dcreate2 --- test/dsets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dsets.c b/test/dsets.c index 2130b39d36a..a60f52ec4f7 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -15795,7 +15795,7 @@ test_downsize_vlen_scalar_dataset(hid_t file) TEST_ERROR; /* Create the scalar dataset of this data type */ - if ((scalar_did = H5Dcreate(file, VLEN_DS_NAME, vlen_compound_file_tid, scalar_sid, H5P_DEFAULT, + if ((scalar_did = H5Dcreate2(file, VLEN_DS_NAME, vlen_compound_file_tid, scalar_sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; From 62d482e61ebcf81111c4fa2117485a0e8fd80099 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 15 Mar 2024 07:18:32 +0000 Subject: [PATCH 4/7] Committing clang-format changes --- test/dsets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dsets.c b/test/dsets.c index a60f52ec4f7..aa2134db839 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -15796,7 +15796,7 @@ test_downsize_vlen_scalar_dataset(hid_t file) /* Create the scalar dataset of this data type */ if ((scalar_did = H5Dcreate2(file, VLEN_DS_NAME, vlen_compound_file_tid, scalar_sid, H5P_DEFAULT, - H5P_DEFAULT, H5P_DEFAULT)) < 0) + H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; /* Setup the variable-length data. Note that if the double "value" field is set to 0.0, the bug will NOT From 0e0b6c77014302491e9c100f89c07b53a9bcd6f5 Mon Sep 17 00:00:00 2001 From: Dana Robinson <43805+derobins@users.noreply.github.com> Date: Fri, 15 Mar 2024 01:13:18 -0700 Subject: [PATCH 5/7] H5Tarray_create --> H5Tarray_create2 --- test/dsets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dsets.c b/test/dsets.c index aa2134db839..ae3baeab4b5 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -15770,7 +15770,7 @@ test_downsize_vlen_scalar_dataset(hid_t file) if (H5Tset_size(string_tid, H5T_VARIABLE) < 0) TEST_ERROR; - if ((string_array_tid = H5Tarray_create(string_tid, 2, array_dims)) < 0) + if ((string_array_tid = H5Tarray_create2(string_tid, 2, array_dims)) < 0) TEST_ERROR; if ((compound_file_tid = H5Tcreate(H5T_COMPOUND, sizeof(vlen_ds_compound_file_t))) < 0) From 65aaff7ab4e3ad1c0ae5aaef94a0ef7a8520a547 Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Fri, 15 Mar 2024 10:20:27 -0500 Subject: [PATCH 6/7] Fix stack variable too large, add RELEASE.txt entry --- release_docs/RELEASE.txt | 10 ++++++++++ test/dsets.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 4c6367e9611..f454fe42e1a 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -577,6 +577,13 @@ Bug Fixes since HDF5-1.14.0 release =================================== Library ------- + - Fixed error when overwriting certain nested variable length types + + Previously, when using a datatype that included a variable length type + within a compound or array within another variable length type, and + overwriting data with a shorter (top level) variable length sequence, an + error could occur. This has been fixed. + - Fixed asserts raised by large values of H5Pset_est_link_info() parameters If large values for est_num_entries and/or est_name_len were passed @@ -1529,6 +1536,9 @@ Known Problems in the HDF5 source. Please report any new problems found to help@hdfgroup.org. + File space may not be released when overwriting or deleting certain nested + variable length or reference types. + CMake vs. Autotools installations ================================= diff --git a/test/dsets.c b/test/dsets.c index 2130b39d36a..34f62bd7a41 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -15752,13 +15752,17 @@ test_downsize_vlen_scalar_dataset(hid_t file) hid_t vlen_compound_memory_tid = -1; /* VARIABLE COMPOUND datatype ID */ hid_t scalar_did = -1; /* SCALAR dataset ID */ hvl_t vlen_compound_data; /* Top-level VLEN data */ - vlen_ds_compound_memory_t compound_data[VLEN_DS_DIM]; /* Contents of VLEN data */ + vlen_ds_compound_memory_t *compound_data = NULL; /* Contents of VLEN data */ char common_string[VLEN_DS_STRLEN]; /* Common string contents */ hsize_t array_dims[2] = {VLEN_DS_ARRAY_DIM1, VLEN_DS_ARRAY_DIM2}; int i, dim1, dim2; /* Local index variables */ TESTING("H5Dwrite() on down-sized VLEN contents"); + /* Allocate space for compound data */ + if (NULL == (compound_data = (vlen_ds_compound_memory_t *)malloc(VLEN_DS_DIM * sizeof(vlen_ds_compound_memory_t)))) + TEST_ERROR; + /* Create scalar dataspace */ if ((scalar_sid = H5Screate(H5S_SCALAR)) < 0) TEST_ERROR; @@ -15822,7 +15826,7 @@ test_downsize_vlen_scalar_dataset(hid_t file) /* Note: the bug in v1.8.14 is tripped on the second iteration, when 100 elements are over-written * with 99. */ for (i = VLEN_DS_DIM; i > 0; --i) { - vlen_compound_data.len = i; + vlen_compound_data.len = (size_t)i; vlen_compound_data.p = compound_data; if (H5Dwrite(scalar_did, vlen_compound_memory_tid, scalar_sid, scalar_sid, H5P_DEFAULT, &vlen_compound_data) < 0) @@ -15846,6 +15850,8 @@ test_downsize_vlen_scalar_dataset(hid_t file) TEST_ERROR; if (H5Dclose(scalar_did) < 0) TEST_ERROR; + free(compound_data); + compound_data = NULL; PASSED(); return 0; @@ -15861,6 +15867,8 @@ test_downsize_vlen_scalar_dataset(hid_t file) H5Tclose(compound_memory_tid); H5Tclose(vlen_compound_memory_tid); H5Dclose(scalar_did); + free(compound_data); + compound_data = NULL; } H5E_END_TRY; return -1; From 5a6956605e827697d8cb9c525cb7303afa1e5b43 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 15 Mar 2024 15:22:49 +0000 Subject: [PATCH 7/7] Committing clang-format changes --- test/dsets.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/test/dsets.c b/test/dsets.c index c970027ef3d..e3b37ad9802 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -15743,24 +15743,25 @@ typedef struct { static herr_t test_downsize_vlen_scalar_dataset(hid_t file) { - hid_t scalar_sid = -1; /* Scalar dataspace ID */ - hid_t string_tid = -1; /* VARIABLE string datatype ID */ - hid_t string_array_tid = -1; /* VARIABLE string array datatype ID */ - hid_t compound_file_tid = -1; /* COMPOUND datatype ID */ - hid_t compound_memory_tid = -1; /* COMPOUND datatype ID */ - hid_t vlen_compound_file_tid = -1; /* VARIABLE COMPOUND datatype ID */ - hid_t vlen_compound_memory_tid = -1; /* VARIABLE COMPOUND datatype ID */ - hid_t scalar_did = -1; /* SCALAR dataset ID */ - hvl_t vlen_compound_data; /* Top-level VLEN data */ - vlen_ds_compound_memory_t *compound_data = NULL; /* Contents of VLEN data */ - char common_string[VLEN_DS_STRLEN]; /* Common string contents */ - hsize_t array_dims[2] = {VLEN_DS_ARRAY_DIM1, VLEN_DS_ARRAY_DIM2}; - int i, dim1, dim2; /* Local index variables */ + hid_t scalar_sid = -1; /* Scalar dataspace ID */ + hid_t string_tid = -1; /* VARIABLE string datatype ID */ + hid_t string_array_tid = -1; /* VARIABLE string array datatype ID */ + hid_t compound_file_tid = -1; /* COMPOUND datatype ID */ + hid_t compound_memory_tid = -1; /* COMPOUND datatype ID */ + hid_t vlen_compound_file_tid = -1; /* VARIABLE COMPOUND datatype ID */ + hid_t vlen_compound_memory_tid = -1; /* VARIABLE COMPOUND datatype ID */ + hid_t scalar_did = -1; /* SCALAR dataset ID */ + hvl_t vlen_compound_data; /* Top-level VLEN data */ + vlen_ds_compound_memory_t *compound_data = NULL; /* Contents of VLEN data */ + char common_string[VLEN_DS_STRLEN]; /* Common string contents */ + hsize_t array_dims[2] = {VLEN_DS_ARRAY_DIM1, VLEN_DS_ARRAY_DIM2}; + int i, dim1, dim2; /* Local index variables */ TESTING("H5Dwrite() on down-sized VLEN contents"); /* Allocate space for compound data */ - if (NULL == (compound_data = (vlen_ds_compound_memory_t *)malloc(VLEN_DS_DIM * sizeof(vlen_ds_compound_memory_t)))) + if (NULL == (compound_data = + (vlen_ds_compound_memory_t *)malloc(VLEN_DS_DIM * sizeof(vlen_ds_compound_memory_t)))) TEST_ERROR; /* Create scalar dataspace */