From b33ab7524a6d290f0bd355f7bfd827ae2e75a4ab Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Tue, 7 Jan 2025 15:41:20 -0600 Subject: [PATCH 01/23] Add H5Tdecode2, rename and deprecate H5Tdecode --- c++/src/H5DataType.cpp | 2 +- fortran/src/H5Tf.c | 5 ++-- fortran/src/H5Tff.F90 | 17 ++++++++------ fortran/src/H5f90proto.h | 2 +- fortran/test/tH5T.F90 | 4 ++-- java/src/hdf/hdf5lib/H5.java | 9 +++++--- src/H5T.c | 24 +++++++++----------- src/H5Tdeprec.c | 44 ++++++++++++++++++++++++++++++++++++ src/H5Tpublic.h | 39 ++++++++++++++++++++++++++++---- src/H5vers.txt | 1 + src/H5version.h | 35 ++++++++++++++++++++++++++++ test/dtypes.c | 14 ++++++------ 12 files changed, 156 insertions(+), 40 deletions(-) diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index e864ed54bb9..b90ba53800f 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -250,7 +250,7 @@ DataType::p_decode() const } // Call C function to decode the binary object description - hid_t encoded_dtype_id = H5Tdecode(encoded_buf); + hid_t encoded_dtype_id = H5Tdecode1(encoded_buf); // If H5Tdecode fails, raise exception if (encoded_dtype_id < 0) { diff --git a/fortran/src/H5Tf.c b/fortran/src/H5Tf.c index f6992f91712..58cc0e1321d 100644 --- a/fortran/src/H5Tf.c +++ b/fortran/src/H5Tf.c @@ -1898,6 +1898,7 @@ h5tcommitted_c(hid_t_f *dtype_id) * INPUTS * * buf - Buffer for the data space object to be decoded. + * buf_size - Size of the buffer * OUTPUTS * * obj_id - Object_id (non-negative) @@ -1908,7 +1909,7 @@ h5tcommitted_c(hid_t_f *dtype_id) */ int_f -h5tdecode_c(_fcd buf, hid_t_f *obj_id) +h5tdecode_c(_fcd buf, size_t_f buf_size, hid_t_f *obj_id) /******/ { int ret_value = -1; @@ -1921,7 +1922,7 @@ h5tdecode_c(_fcd buf, hid_t_f *obj_id) c_buf = (unsigned char *)buf; - c_obj_id = H5Tdecode(c_buf); + c_obj_id = H5Tdecode2(c_buf, buf_size); if (c_obj_id < 0) return ret_value; diff --git a/fortran/src/H5Tff.F90 b/fortran/src/H5Tff.F90 index 1416493e4d7..ca75645523b 100644 --- a/fortran/src/H5Tff.F90 +++ b/fortran/src/H5Tff.F90 @@ -1857,28 +1857,31 @@ END SUBROUTINE h5tcommitted_f !! !! \brief Decode A binary object description of data type and return a new object handle. !! -!! \param buf Buffer for the data space object to be decoded. -!! \param obj_id Object ID. -!! \param hdferr \fortran_error +!! \param buf Buffer for the data space object to be decoded. +!! \param buf_size Size of the buffer. +!! \param obj_id Object ID. +!! \param hdferr \fortran_error !! !! See C API: @ref H5Tdecode() !! - SUBROUTINE h5tdecode_f(buf, obj_id, hdferr) + SUBROUTINE h5tdecode_f(buf, buf_size, obj_id, hdferr) IMPLICIT NONE CHARACTER(LEN=*), INTENT(IN) :: buf + INTEGER(SIZE_T), INTENT(IN) :: buf_size INTEGER(HID_T), INTENT(OUT) :: obj_id INTEGER, INTENT(OUT) :: hdferr INTERFACE - INTEGER FUNCTION h5tdecode_c(buf, obj_id) BIND(C,NAME='h5tdecode_c') + INTEGER FUNCTION h5tdecode_c(buf, buf_size, obj_id) BIND(C,NAME='h5tdecode_c') IMPORT :: C_CHAR - IMPORT :: HID_T + IMPORT :: HID_T, SIZE_T IMPLICIT NONE CHARACTER(KIND=C_CHAR), DIMENSION(*), INTENT(IN) :: buf + INTEGER(SIZE_T), INTENT(IN) :: buf_size INTEGER(HID_T), INTENT(OUT) :: obj_id END FUNCTION h5tdecode_c END INTERFACE - hdferr = h5tdecode_c(buf, obj_id) + hdferr = h5tdecode_c(buf, buf_size, obj_id) END SUBROUTINE h5tdecode_f diff --git a/fortran/src/H5f90proto.h b/fortran/src/H5f90proto.h index 55d36da33b3..60d4b1c5b6c 100644 --- a/fortran/src/H5f90proto.h +++ b/fortran/src/H5f90proto.h @@ -327,7 +327,7 @@ H5_FCDLL int_f h5tvlen_create_c(hid_t_f *type_id, hid_t_f *vltype_id); H5_FCDLL int_f h5tis_variable_str_c(hid_t_f *type_id, int_f *flag); H5_FCDLL int_f h5tget_member_class_c(hid_t_f *type_id, int_f *member_no, int_f *cls); H5_FCDLL int_f h5tcommit_anon_c(hid_t_f *loc_id, hid_t_f *dtype_id, hid_t_f *tcpl_id, hid_t_f *tapl_id); -H5_FCDLL int_f h5tdecode_c(_fcd buf, hid_t_f *obj_id); +H5_FCDLL int_f h5tdecode_c(_fcd buf, size_t_f buf_size, hid_t_f *obj_id); H5_FCDLL int_f h5tencode_c(_fcd buf, hid_t_f *obj_id, size_t_f *nalloc); H5_FCDLL int_f h5tget_create_plist_c(hid_t_f *dtype_id, hid_t_f *dtpl_id); H5_FCDLL int_f h5tcompiler_conv_c(hid_t_f *src_id, hid_t_f *dst_id, int_f *c_flag); diff --git a/fortran/test/tH5T.F90 b/fortran/test/tH5T.F90 index 2e006bc3a4f..27de0911711 100644 --- a/fortran/test/tH5T.F90 +++ b/fortran/test/tH5T.F90 @@ -555,14 +555,14 @@ SUBROUTINE compoundtest(cleanup, total_error) ! Try decoding bogus buffer - CALL H5Tdecode_f(cmpd_buf, decoded_tid1, error) + CALL H5Tdecode_f(cmpd_buf, cmpd_buf_size, decoded_tid1, error) CALL verify("H5Tdecode_f", error, -1, total_error) CALL H5Tencode_f(dtype_id, cmpd_buf, cmpd_buf_size, error) CALL check("H5Tencode_f", error, total_error) ! Decode from the compound buffer and return an object handle - CALL H5Tdecode_f(cmpd_buf, decoded_tid1, error) + CALL H5Tdecode_f(cmpd_buf, cmpd_buf_size, decoded_tid1, error) CALL check("H5Tdecode_f", error, total_error) ! Verify that the datatype was copied exactly diff --git a/java/src/hdf/hdf5lib/H5.java b/java/src/hdf/hdf5lib/H5.java index f630faba8e5..24099adb6a4 100644 --- a/java/src/hdf/hdf5lib/H5.java +++ b/java/src/hdf/hdf5lib/H5.java @@ -13865,6 +13865,9 @@ public static long H5Tcreate(int tclass, long size) throws HDF5LibraryException * @param buf * IN: Buffer for the data type object to be decoded. * + * @param buf_size + * IN: Size of the buffer. + * * @return a new object handle * * @exception HDF5LibraryException @@ -13872,9 +13875,9 @@ public static long H5Tcreate(int tclass, long size) throws HDF5LibraryException * @exception NullPointerException * buf is null. **/ - public static long H5Tdecode(byte[] buf) throws HDF5LibraryException, NullPointerException + public static long H5Tdecode(byte[] buf, long buf_size) throws HDF5LibraryException, NullPointerException { - long id = _H5Tdecode(buf); + long id = _H5Tdecode(buf, buf_size); if (id > 0) { log.trace("OPEN_IDS: H5Tdecode add {}", id); OPEN_IDS.add(id); @@ -13883,7 +13886,7 @@ public static long H5Tdecode(byte[] buf) throws HDF5LibraryException, NullPointe return id; } - private synchronized static native long _H5Tdecode(byte[] buf) + private synchronized static native long _H5Tdecode(byte[] buf, long buf_size) throws HDF5LibraryException, NullPointerException; /** diff --git a/src/H5T.c b/src/H5T.c index 4ad4f2dbf97..a96329f79dc 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -3690,12 +3690,12 @@ H5Tencode(hid_t obj_id, void *buf, size_t *nalloc) FUNC_LEAVE_API(ret_value) } /* end H5Tencode() */ -/*------------------------------------------------------------------------- - * Function: H5Tdecode +/* + * Function: H5Tdecode2 * * Purpose: Decode a binary object description and return a new object * handle. - * + * * Return: Success: datatype ID(non-negative) * * Failure: negative @@ -3703,7 +3703,7 @@ H5Tencode(hid_t obj_id, void *buf, size_t *nalloc) *------------------------------------------------------------------------- */ hid_t -H5Tdecode(const void *buf) +H5Tdecode2(const void *buf, size_t buf_size) { H5T_t *dt; hid_t ret_value; /* Return value */ @@ -3714,13 +3714,8 @@ H5Tdecode(const void *buf) if (buf == NULL) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "empty buffer"); - /* Create datatype by decoding buffer - * There is no way to get the size of the buffer, so we pass in - * SIZE_MAX and assume the caller knows what they are doing. - * Really fixing this will require an H5Tdecode2() call that - * takes a size parameter. - */ - if (NULL == (dt = H5T_decode(SIZE_MAX, (const unsigned char *)buf))) + /* Create datatype by decoding buffer */ + if (NULL == (dt = H5T_decode(buf_size, (const unsigned char *)buf))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, H5I_INVALID_HID, "can't decode object"); /* Register the type and return the ID */ @@ -3729,7 +3724,7 @@ H5Tdecode(const void *buf) done: FUNC_LEAVE_API(ret_value) -} /* end H5Tdecode() */ +} /* end H5Tdecode2() */ /*------------------------------------------------------------------------- * API functions are above; library-private functions are below... @@ -3812,6 +3807,9 @@ H5T_decode(size_t buf_size, const unsigned char *buf) if (NULL == (f = H5F_fake_alloc((uint8_t)0))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, NULL, "can't allocate fake file struct"); + if (buf_size < 2) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "buffer too small to be datatype message"); + /* Decode the type of the information */ if (*buf++ != H5O_DTYPE_ID) HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "not an encoded datatype"); @@ -3821,7 +3819,7 @@ H5T_decode(size_t buf_size, const unsigned char *buf) HGOTO_ERROR(H5E_DATATYPE, H5E_VERSION, NULL, "unknown version of encoded datatype"); /* Decode the serialized datatype message */ - if (NULL == (ret_value = (H5T_t *)H5O_msg_decode(f, NULL, H5O_DTYPE_ID, buf_size, buf))) + if (NULL == (ret_value = (H5T_t *)H5O_msg_decode(f, NULL, H5O_DTYPE_ID, buf_size - 2, buf))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, NULL, "can't decode object"); /* Mark datatype as being in memory now */ diff --git a/src/H5Tdeprec.c b/src/H5Tdeprec.c index 8350cbb8af8..4f4edb53f16 100644 --- a/src/H5Tdeprec.c +++ b/src/H5Tdeprec.c @@ -187,4 +187,48 @@ H5Topen1(hid_t loc_id, const char *name) FUNC_LEAVE_API(ret_value) } /* end H5Topen1() */ + +/*------------------------------------------------------------------------- + * Function: H5Tdecode1 + * + * Purpose: Decode a binary object description and return a new object + * handle. + * + * Note: Deprecated in favor of H5Tdecode2 + * + * Return: Success: datatype ID(non-negative) + * + * Failure: negative + * + *------------------------------------------------------------------------- + */ +hid_t +H5Tdecode1(const void *buf) +{ + H5T_t *dt; + hid_t ret_value; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + + /* Check args */ + if (buf == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "empty buffer"); + + /* Create datatype by decoding buffer + * There is no way to get the size of the buffer, so we pass in + * SIZE_MAX and assume the caller knows what they are doing. + * Really fixing this will require an H5Tdecode2() call that + * takes a size parameter. + */ + if (NULL == (dt = H5T_decode(SIZE_MAX, (const unsigned char *)buf))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, H5I_INVALID_HID, "can't decode object"); + + /* Register the type and return the ID */ + if ((ret_value = H5I_register(H5I_DATATYPE, dt, true)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register data type"); + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Tdecode1() */ + #endif /* H5_NO_DEPRECATED_SYMBOLS */ diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index 83083a48434..2d5fbe31bf9 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -1452,10 +1452,11 @@ H5_DLL herr_t H5Tencode(hid_t obj_id, void *buf, size_t *nalloc); * object handle * * \param[in] buf Buffer for the datatype object to be decoded - * + * \param[in] buf_size Size of the buffer + * * \return \hid_t{datatype} * - * \details H5Tdecode() Given an object description of datatype in binary in a + * \details H5Tdecode2() Given an object description of datatype in binary in a * buffer, H5Tdecode() reconstructs the HDF5 datatype object and * returns a new object handle for it. The binary description of * the object is encoded by H5Tencode(). User is responsible for @@ -1465,10 +1466,11 @@ H5_DLL herr_t H5Tencode(hid_t obj_id, void *buf, size_t *nalloc); * with H5Tclose() when the identifier is no longer needed so that * resource leaks will not develop. * - * \since 1.2.0 + * \since 2.0.0 * */ -H5_DLL hid_t H5Tdecode(const void *buf); +H5_DLL hid_t H5Tdecode2(const void *buf, size_t buf_size); + /** * \ingroup H5T * @@ -2910,6 +2912,35 @@ H5_DLL herr_t H5Treclaim(hid_t type_id, hid_t space_id, hid_t plist_id, void *bu /* Typedefs */ /* Function prototypes */ +/** + * \ingroup H5T + * + * \brief Decodes a binary object description of datatype and returns a new + * object handle + * + * \param[in] buf Buffer for the datatype object to be decoded + * + * \return \hid_t{datatype} + * + * \deprecated This function has been renamed from H5Tdecode() and is + * deprecated in favor of the macro #H5Tdecode or the function + * H5Tdecode2(). + * + * \details H5Tdecode1() Given an object description of datatype in binary in a + * buffer, H5Tdecode() reconstructs the HDF5 datatype object and + * returns a new object handle for it. The binary description of + * the object is encoded by H5Tencode(). User is responsible for + * passing in the right buffer. + * + * The datatype identifier returned by this function can be released + * with H5Tclose() when the identifier is no longer needed so that + * resource leaks will not develop. + * \version 2.0.0 C function H5Tdecode() renamed to H5Tdecode1() and deprecated + * in this release. + * \since 1.2.0 + * + */ +H5_DLL hid_t H5Tdecode1(const void *buf); /** * \ingroup H5T * diff --git a/src/H5vers.txt b/src/H5vers.txt index ce17f889c7b..592c4c37a57 100644 --- a/src/H5vers.txt +++ b/src/H5vers.txt @@ -86,6 +86,7 @@ FUNCTION: H5Tarray_create; ; v14, v18 FUNCTION: H5Tcommit; ; v10, v18 FUNCTION: H5Tget_array_dims; ; v14, v18 FUNCTION: H5Topen; ; v10, v18 +FUNCTION: H5Tdecode; ; v12, v200 # API typedefs # (although not required, it's easier to compare this file with the headers diff --git a/src/H5version.h b/src/H5version.h index 9fe80159695..fdd3b7e5d2e 100644 --- a/src/H5version.h +++ b/src/H5version.h @@ -148,6 +148,10 @@ #define H5Tcommit_vers 1 #endif /* !defined(H5Tcommit_vers) */ +#if !defined(H5Tdecode_vers) + #define H5Tdecode_vers 1 +#endif /* !defined(H5Tdecode_vers) */ + #if !defined(H5Tget_array_dims_vers) #define H5Tget_array_dims_vers 1 #endif /* !defined(H5Tget_array_dims_vers) */ @@ -312,6 +316,10 @@ #define H5Tcommit_vers 2 #endif /* !defined(H5Tcommit_vers) */ +#if !defined(H5Tdecode_vers) + #define H5Tdecode_vers 1 +#endif /* !defined(H5Tdecode_vers) */ + #if !defined(H5Tget_array_dims_vers) #define H5Tget_array_dims_vers 2 #endif /* !defined(H5Tget_array_dims_vers) */ @@ -488,6 +496,10 @@ #define H5Tcommit_vers 2 #endif /* !defined(H5Tcommit_vers) */ +#if !defined(H5Tdecode_vers) + #define H5Tdecode_vers 1 +#endif /* !defined(H5Tdecode_vers) */ + #if !defined(H5Tget_array_dims_vers) #define H5Tget_array_dims_vers 2 #endif /* !defined(H5Tget_array_dims_vers) */ @@ -664,6 +676,10 @@ #define H5Tcommit_vers 2 #endif /* !defined(H5Tcommit_vers) */ +#if !defined(H5Tdecode_vers) + #define H5Tdecode_vers 1 +#endif /* !defined(H5Tdecode_vers) */ + #if !defined(H5Tget_array_dims_vers) #define H5Tget_array_dims_vers 2 #endif /* !defined(H5Tget_array_dims_vers) */ @@ -840,6 +856,10 @@ #define H5Tcommit_vers 2 #endif /* !defined(H5Tcommit_vers) */ +#if !defined(H5Tdecode_vers) + #define H5Tdecode_vers 1 +#endif /* !defined(H5Tdecode_vers) */ + #if !defined(H5Tget_array_dims_vers) #define H5Tget_array_dims_vers 2 #endif /* !defined(H5Tget_array_dims_vers) */ @@ -1016,6 +1036,10 @@ #define H5Tcommit_vers 2 #endif /* !defined(H5Tcommit_vers) */ +#if !defined(H5Tdecode_vers) + #define H5Tdecode_vers 2 +#endif /* !defined(H5Tdecode_vers) */ + #if !defined(H5Tget_array_dims_vers) #define H5Tget_array_dims_vers 2 #endif /* !defined(H5Tget_array_dims_vers) */ @@ -1472,6 +1496,17 @@ #error "H5Tcommit_vers set to invalid value" #endif /* H5Tcommit_vers */ +#if !defined(H5Tdecode_vers) || H5Tdecode_vers == 2 + #ifndef H5Tdecode_vers + #define H5Tdecode_vers 2 + #endif /* H5Tdecode_vers */ + #define H5Tdecode H5Tdecode2 +#elif H5Tdecode_vers == 1 + #define H5Tdecode H5Tdecode1 +#else /* H5Tdecode_vers */ + #error "H5Tdecode_vers set to invalid value" +#endif /* H5Tdecode_vers */ + #if !defined(H5Tget_array_dims_vers) || H5Tget_array_dims_vers == 2 #ifndef H5Tget_array_dims_vers #define H5Tget_array_dims_vers 2 diff --git a/test/dtypes.c b/test/dtypes.c index e0513e4b25f..33c377bf32d 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -9059,7 +9059,7 @@ test_encode(void) /* Try decoding an incorrect (empty) buffer (should fail) */ H5E_BEGIN_TRY { - ret_id = H5Tdecode(cmpd_buf); + ret_id = H5Tdecode(cmpd_buf, cmpd_buf_size); } H5E_END_TRY if (ret_id != FAIL) { @@ -9075,7 +9075,7 @@ test_encode(void) } /* Decode from the compound buffer and return an object handle */ - if ((decoded_tid1 = H5Tdecode(cmpd_buf)) < 0) + if ((decoded_tid1 = H5Tdecode(cmpd_buf, cmpd_buf_size)) < 0) FAIL_PUTS_ERROR("Can't decode compound type\n"); /* Verify that the datatype was copied exactly */ @@ -9114,7 +9114,7 @@ test_encode(void) } /* Decode from the enumerate buffer and return an object handle */ - if ((decoded_tid2 = H5Tdecode(enum_buf)) < 0) { + if ((decoded_tid2 = H5Tdecode(enum_buf, enum_buf_size)) < 0) { H5_FAILED(); printf("Can't decode enumerate type\n"); goto error; @@ -9156,7 +9156,7 @@ test_encode(void) } /* Decode from the VL string buffer and return an object handle */ - if ((decoded_tid3 = H5Tdecode(vlstr_buf)) < 0) { + if ((decoded_tid3 = H5Tdecode(vlstr_buf, vlstr_buf_size)) < 0) { H5_FAILED(); printf("Can't decode VL string type\n"); goto error; @@ -9264,7 +9264,7 @@ test_encode(void) } /* Decode from the compound buffer and return an object handle */ - if ((decoded_tid1 = H5Tdecode(cmpd_buf)) < 0) + if ((decoded_tid1 = H5Tdecode(cmpd_buf, cmpd_buf_size)) < 0) FAIL_PUTS_ERROR("Can't decode compound type\n"); /* Verify that the datatype was copied exactly */ @@ -9303,7 +9303,7 @@ test_encode(void) } /* Decode from the enumerate buffer and return an object handle */ - if ((decoded_tid2 = H5Tdecode(enum_buf)) < 0) { + if ((decoded_tid2 = H5Tdecode(enum_buf, enum_buf_size)) < 0) { H5_FAILED(); printf("Can't decode enumerate type\n"); goto error; @@ -9345,7 +9345,7 @@ test_encode(void) } /* Decode from the VL string buffer and return an object handle */ - if ((decoded_tid3 = H5Tdecode(vlstr_buf)) < 0) { + if ((decoded_tid3 = H5Tdecode(vlstr_buf, vlstr_buf_size)) < 0) { H5_FAILED(); printf("Can't decode VL string type\n"); goto error; From 55c1a6870057980f388781ddbad5451d86599936 Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Tue, 7 Jan 2025 15:46:19 -0600 Subject: [PATCH 02/23] Add RELEASE.txt note about H5Tdecode2 --- release_docs/RELEASE.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 6cf9cfe5b44..b16a16e7f7d 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -178,6 +178,24 @@ New Features H5Iregister_type() will map to the new signature unless the library is explicitly configured to use an older version of the API. + - The H5Tdecode() signature has changed + + When provided malformed or too-small buffers, H5Tdecode() would crash. + The new buffer size parameter allows this to be reliably avoided. + + The old signature has been renamed to H5Tdecode1() and is considered + deprecated: + + hid_t H5Tdecode1(const void *buf); + + The new signature is H5Tdecode2(). New code should use this version: + + hid_t H5Tdecode2(const void *buf, size_t buf_size); + + H5Tdecode() will map to the new signature unless the library is + explicitly configured to use an older version of the API. + + The old signature - H5F_LIBVER_LATEST is now an enum value This was previously #defined to the latest H5F_libver_t API version, but From 6da7a5bf60642167a8981bf087c7a7ce65aa5950 Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Tue, 7 Jan 2025 16:04:53 -0600 Subject: [PATCH 03/23] Use new H5Tdecode2 in tests --- test/dtypes.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/dtypes.c b/test/dtypes.c index 33c377bf32d..cf72a910055 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -9059,7 +9059,7 @@ test_encode(void) /* Try decoding an incorrect (empty) buffer (should fail) */ H5E_BEGIN_TRY { - ret_id = H5Tdecode(cmpd_buf, cmpd_buf_size); + ret_id = H5Tdecode2(cmpd_buf, cmpd_buf_size); } H5E_END_TRY if (ret_id != FAIL) { @@ -9075,7 +9075,7 @@ test_encode(void) } /* Decode from the compound buffer and return an object handle */ - if ((decoded_tid1 = H5Tdecode(cmpd_buf, cmpd_buf_size)) < 0) + if ((decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size)) < 0) FAIL_PUTS_ERROR("Can't decode compound type\n"); /* Verify that the datatype was copied exactly */ @@ -9114,7 +9114,7 @@ test_encode(void) } /* Decode from the enumerate buffer and return an object handle */ - if ((decoded_tid2 = H5Tdecode(enum_buf, enum_buf_size)) < 0) { + if ((decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size)) < 0) { H5_FAILED(); printf("Can't decode enumerate type\n"); goto error; @@ -9156,7 +9156,7 @@ test_encode(void) } /* Decode from the VL string buffer and return an object handle */ - if ((decoded_tid3 = H5Tdecode(vlstr_buf, vlstr_buf_size)) < 0) { + if ((decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size)) < 0) { H5_FAILED(); printf("Can't decode VL string type\n"); goto error; @@ -9264,7 +9264,7 @@ test_encode(void) } /* Decode from the compound buffer and return an object handle */ - if ((decoded_tid1 = H5Tdecode(cmpd_buf, cmpd_buf_size)) < 0) + if ((decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size)) < 0) FAIL_PUTS_ERROR("Can't decode compound type\n"); /* Verify that the datatype was copied exactly */ @@ -9303,7 +9303,7 @@ test_encode(void) } /* Decode from the enumerate buffer and return an object handle */ - if ((decoded_tid2 = H5Tdecode(enum_buf, enum_buf_size)) < 0) { + if ((decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size)) < 0) { H5_FAILED(); printf("Can't decode enumerate type\n"); goto error; @@ -9345,7 +9345,7 @@ test_encode(void) } /* Decode from the VL string buffer and return an object handle */ - if ((decoded_tid3 = H5Tdecode(vlstr_buf, vlstr_buf_size)) < 0) { + if ((decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size)) < 0) { H5_FAILED(); printf("Can't decode VL string type\n"); goto error; From d941398a800b9fc1520387f37a0e686f5bc1d00f Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Tue, 7 Jan 2025 16:15:16 -0600 Subject: [PATCH 04/23] Clang-format changes --- java/src/hdf/hdf5lib/H5.java | 2 +- src/H5T.c | 2 +- src/H5Tdeprec.c | 2 +- src/H5Tpublic.h | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/java/src/hdf/hdf5lib/H5.java b/java/src/hdf/hdf5lib/H5.java index 24099adb6a4..d8b778e6ad2 100644 --- a/java/src/hdf/hdf5lib/H5.java +++ b/java/src/hdf/hdf5lib/H5.java @@ -13867,7 +13867,7 @@ public static long H5Tcreate(int tclass, long size) throws HDF5LibraryException * * @param buf_size * IN: Size of the buffer. - * + * * @return a new object handle * * @exception HDF5LibraryException diff --git a/src/H5T.c b/src/H5T.c index a96329f79dc..1824d1c7ffc 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -3695,7 +3695,7 @@ H5Tencode(hid_t obj_id, void *buf, size_t *nalloc) * * Purpose: Decode a binary object description and return a new object * handle. - * + * * Return: Success: datatype ID(non-negative) * * Failure: negative diff --git a/src/H5Tdeprec.c b/src/H5Tdeprec.c index 4f4edb53f16..3c9bdf97fcc 100644 --- a/src/H5Tdeprec.c +++ b/src/H5Tdeprec.c @@ -195,7 +195,7 @@ H5Topen1(hid_t loc_id, const char *name) * handle. * * Note: Deprecated in favor of H5Tdecode2 - * + * * Return: Success: datatype ID(non-negative) * * Failure: negative diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index 2d5fbe31bf9..2cd5957bd66 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -1313,7 +1313,7 @@ H5_DLL hid_t H5Topen2(hid_t loc_id, const char *name, hid_t tapl_id); H5_DLL hid_t H5Topen_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name, hid_t tapl_id, hid_t es_id); #else -H5_DLL hid_t H5Topen_async(hid_t loc_id, const char *name, hid_t tapl_id, hid_t es_id); +H5_DLL hid_t H5Topen_async(hid_t loc_id, const char *name, hid_t tapl_id, hid_t es_id); #endif /** * \ingroup H5T @@ -1453,7 +1453,7 @@ H5_DLL herr_t H5Tencode(hid_t obj_id, void *buf, size_t *nalloc); * * \param[in] buf Buffer for the datatype object to be decoded * \param[in] buf_size Size of the buffer - * + * * \return \hid_t{datatype} * * \details H5Tdecode2() Given an object description of datatype in binary in a @@ -2925,7 +2925,7 @@ H5_DLL herr_t H5Treclaim(hid_t type_id, hid_t space_id, hid_t plist_id, void *bu * \deprecated This function has been renamed from H5Tdecode() and is * deprecated in favor of the macro #H5Tdecode or the function * H5Tdecode2(). - * + * * \details H5Tdecode1() Given an object description of datatype in binary in a * buffer, H5Tdecode() reconstructs the HDF5 datatype object and * returns a new object handle for it. The binary description of From 6981bc02f28f5289cfb97d672e8781acf3aa451d Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 8 Jan 2025 08:55:06 -0600 Subject: [PATCH 05/23] Use H5Tdecode2 in CPP wrapper --- c++/src/H5DataType.cpp | 2 +- src/H5Tpublic.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index b90ba53800f..7414ef226dd 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -250,7 +250,7 @@ DataType::p_decode() const } // Call C function to decode the binary object description - hid_t encoded_dtype_id = H5Tdecode1(encoded_buf); + hid_t encoded_dtype_id = H5Tdecode2(encoded_buf, buf_size); // If H5Tdecode fails, raise exception if (encoded_dtype_id < 0) { diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index 2cd5957bd66..8b885cea4e2 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -1313,7 +1313,7 @@ H5_DLL hid_t H5Topen2(hid_t loc_id, const char *name, hid_t tapl_id); H5_DLL hid_t H5Topen_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name, hid_t tapl_id, hid_t es_id); #else -H5_DLL hid_t H5Topen_async(hid_t loc_id, const char *name, hid_t tapl_id, hid_t es_id); +H5_DLL hid_t H5Topen_async(hid_t loc_id, const char *name, hid_t tapl_id, hid_t es_id); #endif /** * \ingroup H5T From 30730d43d72983ad3b0f81e7cf70f188a58f6d62 Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 8 Jan 2025 10:00:38 -0600 Subject: [PATCH 06/23] Fix typo in RELEASE --- release_docs/RELEASE.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index b16a16e7f7d..1f5f3c99cab 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -190,12 +190,11 @@ New Features The new signature is H5Tdecode2(). New code should use this version: - hid_t H5Tdecode2(const void *buf, size_t buf_size); + hid_t H5Tdecode2(const void *buf, size_t buf_size); H5Tdecode() will map to the new signature unless the library is explicitly configured to use an older version of the API. - The old signature - H5F_LIBVER_LATEST is now an enum value This was previously #defined to the latest H5F_libver_t API version, but From b1c6e2dbeec4706c416f94c5f6352eb572cafd9f Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 8 Jan 2025 10:27:17 -0600 Subject: [PATCH 07/23] Add test case for H5Tdecode1 --- test/dtypes.c | 91 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 18 deletions(-) diff --git a/test/dtypes.c b/test/dtypes.c index cf72a910055..931f2021320 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -853,10 +853,10 @@ test_compound_2(void) { struct st { int a, b, c[4], d, e; - } *s_ptr; + } * s_ptr; struct dt { int e, d, c[4], b, a; - } *d_ptr; + } * d_ptr; const size_t nelmts = NTESTELEM; const hsize_t four = 4; @@ -978,10 +978,10 @@ test_compound_3(void) { struct st { int a, b, c[4], d, e; - } *s_ptr; + } * s_ptr; struct dt { int a, c[4], e; - } *d_ptr; + } * d_ptr; const size_t nelmts = NTESTELEM; const hsize_t four = 4; @@ -1100,13 +1100,13 @@ test_compound_4(void) struct st { int a, b, c[4], d, e; - } *s_ptr; + } * s_ptr; struct dt { short b; int a, c[4]; short d; int e; - } *d_ptr; + } * d_ptr; const size_t nelmts = NTESTELEM; const hsize_t four = 4; @@ -1328,11 +1328,11 @@ test_compound_6(void) struct st { short b; short d; - } *s_ptr; + } * s_ptr; struct dt { long b; long d; - } *d_ptr; + } * d_ptr; const size_t nelmts = NTESTELEM; unsigned char *buf = NULL, *orig = NULL, *bkg = NULL; @@ -8926,7 +8926,7 @@ test_set_size_invalid(void) *------------------------------------------------------------------------- */ static int -test_encode(void) +test_encode(bool use_old_decode_api) { struct cmpd { int a; @@ -8954,8 +8954,14 @@ test_encode(void) unsigned char *vlstr_buf = NULL; hid_t ret_id; herr_t ret; + char test_msg[128]; - TESTING("functions of encoding and decoding datatypes"); + /* Silence unused parameter warning if built with no deprecated symbols */ + (void)use_old_decode_api; + + snprintf(test_msg, sizeof(test_msg), "%s functions of encoding and decoding datatypes", + use_old_decode_api ? "old" : "new"); + TESTING(test_msg); /* Create File */ h5_fixname(FILENAME[5], H5P_DEFAULT, filename, sizeof filename); @@ -9059,7 +9065,12 @@ test_encode(void) /* Try decoding an incorrect (empty) buffer (should fail) */ H5E_BEGIN_TRY { - ret_id = H5Tdecode2(cmpd_buf, cmpd_buf_size); +#ifndef H5_NO_DEPRECATED_SYMBOLS + if (use_old_decode_api) + ret_id = H5Tdecode1(cmpd_buf); + else +#endif + ret_id = H5Tdecode2(cmpd_buf, cmpd_buf_size); } H5E_END_TRY if (ret_id != FAIL) { @@ -9075,7 +9086,14 @@ test_encode(void) } /* Decode from the compound buffer and return an object handle */ - if ((decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size)) < 0) +#ifndef H5_NO_DEPRECATED_SYMBOLS + if (use_old_decode_api) + decoded_tid1 = H5Tdecode1(cmpd_buf); + else +#endif + decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size); + + if (decoded_tid1 < 0) FAIL_PUTS_ERROR("Can't decode compound type\n"); /* Verify that the datatype was copied exactly */ @@ -9114,7 +9132,14 @@ test_encode(void) } /* Decode from the enumerate buffer and return an object handle */ - if ((decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size)) < 0) { +#ifndef H5_NO_DEPRECATED_SYMBOLS + if (use_old_decode_api) + decoded_tid2 = H5Tdecode1(enum_buf); + else +#endif + decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size); + + if (decoded_tid2 < 0) { H5_FAILED(); printf("Can't decode enumerate type\n"); goto error; @@ -9156,7 +9181,14 @@ test_encode(void) } /* Decode from the VL string buffer and return an object handle */ - if ((decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size)) < 0) { +#ifndef H5_NO_DEPRECATED_SYMBOLS + if (use_old_decode_api) + decoded_tid3 = H5Tdecode1(vlstr_buf); + else +#endif + decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size); + + if (decoded_tid3 < 0) { H5_FAILED(); printf("Can't decode VL string type\n"); goto error; @@ -9264,7 +9296,14 @@ test_encode(void) } /* Decode from the compound buffer and return an object handle */ - if ((decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size)) < 0) +#ifndef H5_NO_DEPRECATED_SYMBOLS + if (use_old_decode_api) + decoded_tid1 = H5Tdecode1(cmpd_buf); + else +#endif + decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size); + + if (decoded_tid1 < 0) FAIL_PUTS_ERROR("Can't decode compound type\n"); /* Verify that the datatype was copied exactly */ @@ -9303,7 +9342,14 @@ test_encode(void) } /* Decode from the enumerate buffer and return an object handle */ - if ((decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size)) < 0) { +#ifndef H5_NO_DEPRECATED_SYMBOLS + if (use_old_decode_api) + decoded_tid2 = H5Tdecode1(enum_buf); + else +#endif + decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size); + + if (decoded_tid2 < 0) { H5_FAILED(); printf("Can't decode enumerate type\n"); goto error; @@ -9345,11 +9391,19 @@ test_encode(void) } /* Decode from the VL string buffer and return an object handle */ - if ((decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size)) < 0) { +#ifndef H5_NO_DEPRECATED_SYMBOLS + if (use_old_decode_api) + decoded_tid3 = H5Tdecode1(vlstr_buf); + else +#endif + decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size); + + if (decoded_tid3 < 0) { H5_FAILED(); printf("Can't decode VL string type\n"); goto error; } + free(vlstr_buf); /* Verify that the datatype was copied exactly */ @@ -12825,7 +12879,7 @@ main(void) nerrors += test_set_fields_offset(); nerrors += test_transient(fapl); nerrors += test_named(fapl); - nerrors += test_encode(); + nerrors += test_encode(false); nerrors += test_latest(); nerrors += test_int_float_except(); nerrors += test_named_indirect_reopen(fapl); @@ -12836,6 +12890,7 @@ main(void) nerrors += test_enum_member_order(); nerrors += test_str_create(); #ifndef H5_NO_DEPRECATED_SYMBOLS + nerrors += test_encode(true); nerrors += test_deprec(fapl); #endif /* H5_NO_DEPRECATED_SYMBOLS */ From a53b1adc3aa6842b5f83887b82a6689c335af00b Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 8 Jan 2025 10:44:23 -0600 Subject: [PATCH 08/23] Fix H5Tdecode1 failures --- src/H5T.c | 2 +- test/dtypes.c | 49 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/H5T.c b/src/H5T.c index 1824d1c7ffc..af8e47ed843 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -3819,7 +3819,7 @@ H5T_decode(size_t buf_size, const unsigned char *buf) HGOTO_ERROR(H5E_DATATYPE, H5E_VERSION, NULL, "unknown version of encoded datatype"); /* Decode the serialized datatype message */ - if (NULL == (ret_value = (H5T_t *)H5O_msg_decode(f, NULL, H5O_DTYPE_ID, buf_size - 2, buf))) + if (NULL == (ret_value = (H5T_t *)H5O_msg_decode(f, NULL, H5O_DTYPE_ID, buf_size, buf))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, NULL, "can't decode object"); /* Mark datatype as being in memory now */ diff --git a/test/dtypes.c b/test/dtypes.c index 931f2021320..93b962dc96a 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -853,10 +853,10 @@ test_compound_2(void) { struct st { int a, b, c[4], d, e; - } * s_ptr; + } *s_ptr; struct dt { int e, d, c[4], b, a; - } * d_ptr; + } *d_ptr; const size_t nelmts = NTESTELEM; const hsize_t four = 4; @@ -978,10 +978,10 @@ test_compound_3(void) { struct st { int a, b, c[4], d, e; - } * s_ptr; + } *s_ptr; struct dt { int a, c[4], e; - } * d_ptr; + } *d_ptr; const size_t nelmts = NTESTELEM; const hsize_t four = 4; @@ -1100,13 +1100,13 @@ test_compound_4(void) struct st { int a, b, c[4], d, e; - } * s_ptr; + } *s_ptr; struct dt { short b; int a, c[4]; short d; int e; - } * d_ptr; + } *d_ptr; const size_t nelmts = NTESTELEM; const hsize_t four = 4; @@ -1328,11 +1328,11 @@ test_compound_6(void) struct st { short b; short d; - } * s_ptr; + } *s_ptr; struct dt { long b; long d; - } * d_ptr; + } *d_ptr; const size_t nelmts = NTESTELEM; unsigned char *buf = NULL, *orig = NULL, *bkg = NULL; @@ -9069,8 +9069,11 @@ test_encode(bool use_old_decode_api) if (use_old_decode_api) ret_id = H5Tdecode1(cmpd_buf); else -#endif ret_id = H5Tdecode2(cmpd_buf, cmpd_buf_size); +#else + ret_id = H5Tdecode2(cmpd_buf, cmpd_buf_size); +#endif + } H5E_END_TRY if (ret_id != FAIL) { @@ -9090,8 +9093,10 @@ test_encode(bool use_old_decode_api) if (use_old_decode_api) decoded_tid1 = H5Tdecode1(cmpd_buf); else -#endif decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size); +#else + decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size); +#endif if (decoded_tid1 < 0) FAIL_PUTS_ERROR("Can't decode compound type\n"); @@ -9136,8 +9141,10 @@ test_encode(bool use_old_decode_api) if (use_old_decode_api) decoded_tid2 = H5Tdecode1(enum_buf); else -#endif decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size); +#else + decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size); +#endif if (decoded_tid2 < 0) { H5_FAILED(); @@ -9185,8 +9192,10 @@ test_encode(bool use_old_decode_api) if (use_old_decode_api) decoded_tid3 = H5Tdecode1(vlstr_buf); else -#endif decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size); +#else + decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size); +#endif if (decoded_tid3 < 0) { H5_FAILED(); @@ -9300,8 +9309,10 @@ test_encode(bool use_old_decode_api) if (use_old_decode_api) decoded_tid1 = H5Tdecode1(cmpd_buf); else -#endif decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size); +#else + decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size); +#endif if (decoded_tid1 < 0) FAIL_PUTS_ERROR("Can't decode compound type\n"); @@ -9346,8 +9357,10 @@ test_encode(bool use_old_decode_api) if (use_old_decode_api) decoded_tid2 = H5Tdecode1(enum_buf); else -#endif decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size); +#else + decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size); +#endif if (decoded_tid2 < 0) { H5_FAILED(); @@ -9395,8 +9408,10 @@ test_encode(bool use_old_decode_api) if (use_old_decode_api) decoded_tid3 = H5Tdecode1(vlstr_buf); else -#endif decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size); +#else + decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size); +#endif if (decoded_tid3 < 0) { H5_FAILED(); @@ -12879,6 +12894,9 @@ main(void) nerrors += test_set_fields_offset(); nerrors += test_transient(fapl); nerrors += test_named(fapl); +#ifndef H5_NO_DEPRECATED_SYMBOLS + nerrors += test_encode(true); +#endif /* H5_NO_DEPRECATED_SYMBOLS */ nerrors += test_encode(false); nerrors += test_latest(); nerrors += test_int_float_except(); @@ -12890,7 +12908,6 @@ main(void) nerrors += test_enum_member_order(); nerrors += test_str_create(); #ifndef H5_NO_DEPRECATED_SYMBOLS - nerrors += test_encode(true); nerrors += test_deprec(fapl); #endif /* H5_NO_DEPRECATED_SYMBOLS */ From 239c311dc24d734690fe9857beb144b1880c5835 Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 8 Jan 2025 10:49:52 -0600 Subject: [PATCH 09/23] Clang-format changes --- test/dtypes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/dtypes.c b/test/dtypes.c index 93b962dc96a..7cab6599a77 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -9073,7 +9073,6 @@ test_encode(bool use_old_decode_api) #else ret_id = H5Tdecode2(cmpd_buf, cmpd_buf_size); #endif - } H5E_END_TRY if (ret_id != FAIL) { @@ -9143,7 +9142,7 @@ test_encode(bool use_old_decode_api) else decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size); #else - decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size); + decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size); #endif if (decoded_tid2 < 0) { From 9b2e54a9595714f4304d4f5c6cb854255ab256a4 Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 8 Jan 2025 11:12:58 -0600 Subject: [PATCH 10/23] Retrieve buf size before decode in CPP wrapper --- c++/src/H5DataType.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index 7414ef226dd..c0349b316ef 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -249,6 +249,15 @@ DataType::p_decode() const throw DataTypeIException("DataType::p_decode", "No encoded buffer"); } + // Retrieve datatype size + if (H5Tencode(id, NULL, &buf_size) < 0) { + throw DataTypeIException("DataType::p_decode", "Unable to retrieve encoded buffer size"); + } + + if (buf_size == 0) { + throw DataTypeIException("DataType::p_decode", "Invalid encoded buffer size"); + } + // Call C function to decode the binary object description hid_t encoded_dtype_id = H5Tdecode2(encoded_buf, buf_size); From fd8e1c2a0ecd948737e51a760235b5cb225ceb4c Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 8 Jan 2025 15:27:01 -0600 Subject: [PATCH 11/23] Remove redundant size check --- c++/src/H5DataType.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index c0349b316ef..dd80a260c16 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -249,15 +249,6 @@ DataType::p_decode() const throw DataTypeIException("DataType::p_decode", "No encoded buffer"); } - // Retrieve datatype size - if (H5Tencode(id, NULL, &buf_size) < 0) { - throw DataTypeIException("DataType::p_decode", "Unable to retrieve encoded buffer size"); - } - - if (buf_size == 0) { - throw DataTypeIException("DataType::p_decode", "Invalid encoded buffer size"); - } - // Call C function to decode the binary object description hid_t encoded_dtype_id = H5Tdecode2(encoded_buf, buf_size); @@ -933,6 +924,7 @@ DataType::close() // Free and reset buffer of encoded object description if it's been used if (encoded_buf != NULL) { delete[] encoded_buf; + encoded_buf = NULL; buf_size = 0; } } From cc0bbc407bc96388e769489c50b9d83d86e74a50 Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 8 Jan 2025 15:27:16 -0600 Subject: [PATCH 12/23] Use H5_IS_BUFFER_OVERFLOW to check buf size --- src/H5T.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/H5T.c b/src/H5T.c index af8e47ed843..724cde6a931 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -3690,7 +3690,7 @@ H5Tencode(hid_t obj_id, void *buf, size_t *nalloc) FUNC_LEAVE_API(ret_value) } /* end H5Tencode() */ -/* +/*------------------------------------------------------------------------- * Function: H5Tdecode2 * * Purpose: Decode a binary object description and return a new object @@ -3807,13 +3807,16 @@ H5T_decode(size_t buf_size, const unsigned char *buf) if (NULL == (f = H5F_fake_alloc((uint8_t)0))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, NULL, "can't allocate fake file struct"); - if (buf_size < 2) + if (H5_IS_BUFFER_OVERFLOW(buf, buf_size, 1)) HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "buffer too small to be datatype message"); /* Decode the type of the information */ if (*buf++ != H5O_DTYPE_ID) HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "not an encoded datatype"); + if (H5_IS_BUFFER_OVERFLOW(buf, buf_size, 1)) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "buffer too small to be datatype message"); + /* Decode the version of the datatype information */ if (*buf++ != H5T_ENCODE_VERSION) HGOTO_ERROR(H5E_DATATYPE, H5E_VERSION, NULL, "unknown version of encoded datatype"); From b6bf81a8e2370de1f2177abcf4f53c9a29eaeda4 Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 8 Jan 2025 15:28:44 -0600 Subject: [PATCH 13/23] Fix typo in doxygen --- src/H5T.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/H5T.c b/src/H5T.c index 724cde6a931..641347f1a5b 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -3715,7 +3715,7 @@ H5Tdecode2(const void *buf, size_t buf_size) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "empty buffer"); /* Create datatype by decoding buffer */ - if (NULL == (dt = H5T_decode(buf_size, (const unsigned char *)buf))) + if (NULL == (dt = H5T_decode(buf_size, buf))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, H5I_INVALID_HID, "can't decode object"); /* Register the type and return the ID */ From efc00ea5a9315046fe9ffdbcc5402c95878c4748 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 21:30:56 +0000 Subject: [PATCH 14/23] Fix buffer checks --- c++/src/H5DataType.cpp | 2 +- src/H5T.c | 4 ++-- src/H5Tpublic.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index dd80a260c16..55a32eac2a7 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -925,7 +925,7 @@ DataType::close() if (encoded_buf != NULL) { delete[] encoded_buf; encoded_buf = NULL; - buf_size = 0; + buf_size = 0; } } } diff --git a/src/H5T.c b/src/H5T.c index 641347f1a5b..a334674b4a9 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -3807,14 +3807,14 @@ H5T_decode(size_t buf_size, const unsigned char *buf) if (NULL == (f = H5F_fake_alloc((uint8_t)0))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, NULL, "can't allocate fake file struct"); - if (H5_IS_BUFFER_OVERFLOW(buf, buf_size, 1)) + if (buf_size != SIZE_MAX && H5_IS_BUFFER_OVERFLOW(buf, 1, buf + buf_size)) HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "buffer too small to be datatype message"); /* Decode the type of the information */ if (*buf++ != H5O_DTYPE_ID) HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "not an encoded datatype"); - if (H5_IS_BUFFER_OVERFLOW(buf, buf_size, 1)) + if (buf_size != SIZE_MAX && H5_IS_BUFFER_OVERFLOW(buf, 1, buf + buf_size)) HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "buffer too small to be datatype message"); /* Decode the version of the datatype information */ diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index 8b885cea4e2..aae96ea951f 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -1457,7 +1457,7 @@ H5_DLL herr_t H5Tencode(hid_t obj_id, void *buf, size_t *nalloc); * \return \hid_t{datatype} * * \details H5Tdecode2() Given an object description of datatype in binary in a - * buffer, H5Tdecode() reconstructs the HDF5 datatype object and + * buffer, H5Tdecode2() reconstructs the HDF5 datatype object and * returns a new object handle for it. The binary description of * the object is encoded by H5Tencode(). User is responsible for * passing in the right buffer. From 96e5e14d1ba125a6152d24469fe776ceb5a1b9c2 Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Tue, 14 Jan 2025 10:52:38 -0600 Subject: [PATCH 15/23] Exclude null byte from buffer overflow checks --- src/H5T.c | 4 ++-- test/dtypes.c | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/H5T.c b/src/H5T.c index a334674b4a9..c089f6aa989 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -3807,14 +3807,14 @@ H5T_decode(size_t buf_size, const unsigned char *buf) if (NULL == (f = H5F_fake_alloc((uint8_t)0))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, NULL, "can't allocate fake file struct"); - if (buf_size != SIZE_MAX && H5_IS_BUFFER_OVERFLOW(buf, 1, buf + buf_size)) + if (buf_size != SIZE_MAX && H5_IS_BUFFER_OVERFLOW(buf, 1, buf + buf_size - 1)) HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "buffer too small to be datatype message"); /* Decode the type of the information */ if (*buf++ != H5O_DTYPE_ID) HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "not an encoded datatype"); - if (buf_size != SIZE_MAX && H5_IS_BUFFER_OVERFLOW(buf, 1, buf + buf_size)) + if (buf_size != SIZE_MAX && H5_IS_BUFFER_OVERFLOW(buf, 1, buf + buf_size - 1)) HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "buffer too small to be datatype message"); /* Decode the version of the datatype information */ diff --git a/test/dtypes.c b/test/dtypes.c index 7cab6599a77..3863f492523 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -8926,7 +8926,7 @@ test_set_size_invalid(void) *------------------------------------------------------------------------- */ static int -test_encode(bool use_old_decode_api) +test_encode(bool H5_ATTR_DEPRECATED_USED use_old_decode_api) { struct cmpd { int a; @@ -8956,9 +8956,6 @@ test_encode(bool use_old_decode_api) herr_t ret; char test_msg[128]; - /* Silence unused parameter warning if built with no deprecated symbols */ - (void)use_old_decode_api; - snprintf(test_msg, sizeof(test_msg), "%s functions of encoding and decoding datatypes", use_old_decode_api ? "old" : "new"); TESTING(test_msg); From f1a3c477bcf96bd5949f3a66ab83473c2b6dd9c1 Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 15 Jan 2025 08:17:30 -0600 Subject: [PATCH 16/23] Use overloading in Fortran wrapper --- fortran/src/H5Tff.F90 | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/fortran/src/H5Tff.F90 b/fortran/src/H5Tff.F90 index ca75645523b..ec80977e19f 100644 --- a/fortran/src/H5Tff.F90 +++ b/fortran/src/H5Tff.F90 @@ -58,6 +58,11 @@ MODULE H5T #endif +INTERFACE h5tdecode_f + MODULE PROCEDURE h5tdecode_with_size_f + MODULE PROCEDURE h5tdecode_auto_size_f +END INTERFACE h5tdecode_f + CONTAINS !> @@ -1862,9 +1867,9 @@ END SUBROUTINE h5tcommitted_f !! \param obj_id Object ID. !! \param hdferr \fortran_error !! -!! See C API: @ref H5Tdecode() +!! See C API: @ref H5Tdecode2() !! - SUBROUTINE h5tdecode_f(buf, buf_size, obj_id, hdferr) +SUBROUTINE h5tdecode_with_size_f(buf, buf_size, obj_id, hdferr) IMPLICIT NONE CHARACTER(LEN=*), INTENT(IN) :: buf INTEGER(SIZE_T), INTENT(IN) :: buf_size @@ -1882,8 +1887,39 @@ END FUNCTION h5tdecode_c END INTERFACE hdferr = h5tdecode_c(buf, buf_size, obj_id) +END SUBROUTINE h5tdecode_with_size_f - END SUBROUTINE h5tdecode_f +!> +!! \ingroup FH5T +!! +!! \brief Decode A binary object description of data type and return a new object handle. +!! +!! \param buf Buffer for the data space object to be decoded. +!! \param obj_id Object ID. +!! \param hdferr \fortran_error +!! +!! See C API: @ref H5Tdecode2() +!! +SUBROUTINE h5tdecode_auto_size_f(buf, obj_id, hdferr) + IMPLICIT NONE + CHARACTER(LEN=*), INTENT(IN) :: buf + INTEGER(HID_T), INTENT(OUT) :: obj_id + INTEGER, INTENT(OUT) :: hdferr + INTEGER(SIZE_T) :: buf_size + INTERFACE + INTEGER FUNCTION h5tdecode_c(buf, buf_size, obj_id) BIND(C,NAME='h5tdecode_c') + IMPORT :: C_CHAR + IMPORT :: HID_T, SIZE_T + IMPLICIT NONE + CHARACTER(KIND=C_CHAR), DIMENSION(*), INTENT(IN) :: buf + INTEGER(SIZE_T), INTENT(IN) :: buf_size + INTEGER(HID_T), INTENT(OUT) :: obj_id + END FUNCTION h5tdecode_c + END INTERFACE + + buf_size = LEN(buf) + hdferr = h5tdecode_c(buf, buf_size, obj_id) +END SUBROUTINE h5tdecode_auto_size_f !> !! \ingroup FH5T From a6b0c79ad8022c1fc2d858c433a109c70d39f4db Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 15 Jan 2025 08:25:23 -0600 Subject: [PATCH 17/23] Add automatic size fortran test --- fortran/test/tH5T.F90 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fortran/test/tH5T.F90 b/fortran/test/tH5T.F90 index 27de0911711..ae131cf16e7 100644 --- a/fortran/test/tH5T.F90 +++ b/fortran/test/tH5T.F90 @@ -109,6 +109,7 @@ SUBROUTINE compoundtest(cleanup, total_error) CHARACTER(LEN=1024) :: cmpd_buf INTEGER(SIZE_T) :: cmpd_buf_size=0 INTEGER(HID_T) :: decoded_tid1 + INTEGER(HID_T) :: decoded_tid2 INTEGER(HID_T) :: fixed_str1, fixed_str2 LOGICAL :: are_equal @@ -558,6 +559,11 @@ SUBROUTINE compoundtest(cleanup, total_error) CALL H5Tdecode_f(cmpd_buf, cmpd_buf_size, decoded_tid1, error) CALL verify("H5Tdecode_f", error, -1, total_error) + ! Try decoding bogus buffer with automatic size detection + + CALL H5Tdecode_f(cmpd_buf, decoded_tid1, error) + CALL verify("H5Tdecode_f", error, -1, total_error) + CALL H5Tencode_f(dtype_id, cmpd_buf, cmpd_buf_size, error) CALL check("H5Tencode_f", error, total_error) @@ -570,6 +576,15 @@ SUBROUTINE compoundtest(cleanup, total_error) CALL H5Tequal_f(decoded_tid1, dtype_id, flag, error) CALL check("H5Tequal_f", error, total_error) CALL verify("H5Tequal_f", flag, .TRUE., total_error) + + ! Decode from the compound buffer with automatic size detection + CALL H5Tdecode_f(cmpd_buf, decoded_tid2, error) + CALL check("H5Tdecode_f", error, total_error) + + ! Verify that the datatype was copied exactly + CALL H5Tequal_f(decoded_tid2, dtype_id, flag, error) + CALL check("H5Tequal_f", error, total_error) + ! ! Close all open objects. ! From a4a1ad076515801009033c42f7e9a9ca41810c5a Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 15 Jan 2025 10:06:32 -0600 Subject: [PATCH 18/23] Fix symbol export on windows --- fortran/src/hdf5_fortrandll.def.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fortran/src/hdf5_fortrandll.def.in b/fortran/src/hdf5_fortrandll.def.in index 5bc4a274c42..d7b9b8a46de 100644 --- a/fortran/src/hdf5_fortrandll.def.in +++ b/fortran/src/hdf5_fortrandll.def.in @@ -575,7 +575,8 @@ H5T_mp_H5TIS_VARIABLE_STR_F H5T_mp_H5TGET_MEMBER_CLASS_F H5T_mp_H5TCOMMIT_ANON_F H5T_mp_H5TCOMMITTED_F -H5T_mp_H5TDECODE_F +H5T_mp_H5TDECODE_WITH_SIZE_F +H5T_mp_H5TDECODE_AUTO_SIZE_F H5T_mp_H5TENCODE_F H5T_mp_H5TGET_CREATE_PLIST_F H5T_mp_H5TCOMPILER_CONV_F From 9e876285a99325a6bce1b21bf0da49d76254ad3c Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 15 Jan 2025 10:20:13 -0600 Subject: [PATCH 19/23] Update first H5Tdecode1 ver from 1.2 -> 1.8 --- src/H5Tpublic.h | 2 +- src/H5vers.txt | 2 +- src/H5version.h | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index aae96ea951f..28670b4dfb3 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -2937,7 +2937,7 @@ H5_DLL herr_t H5Treclaim(hid_t type_id, hid_t space_id, hid_t plist_id, void *bu * resource leaks will not develop. * \version 2.0.0 C function H5Tdecode() renamed to H5Tdecode1() and deprecated * in this release. - * \since 1.2.0 + * \since 1.8.0 * */ H5_DLL hid_t H5Tdecode1(const void *buf); diff --git a/src/H5vers.txt b/src/H5vers.txt index 592c4c37a57..de65f1298c1 100644 --- a/src/H5vers.txt +++ b/src/H5vers.txt @@ -86,7 +86,7 @@ FUNCTION: H5Tarray_create; ; v14, v18 FUNCTION: H5Tcommit; ; v10, v18 FUNCTION: H5Tget_array_dims; ; v14, v18 FUNCTION: H5Topen; ; v10, v18 -FUNCTION: H5Tdecode; ; v12, v200 +FUNCTION: H5Tdecode; ; v18, v200 # API typedefs # (although not required, it's easier to compare this file with the headers diff --git a/src/H5version.h b/src/H5version.h index fdd3b7e5d2e..55b2e22ff55 100644 --- a/src/H5version.h +++ b/src/H5version.h @@ -148,10 +148,6 @@ #define H5Tcommit_vers 1 #endif /* !defined(H5Tcommit_vers) */ -#if !defined(H5Tdecode_vers) - #define H5Tdecode_vers 1 -#endif /* !defined(H5Tdecode_vers) */ - #if !defined(H5Tget_array_dims_vers) #define H5Tget_array_dims_vers 1 #endif /* !defined(H5Tget_array_dims_vers) */ From 10c1cf4f29b2edcd0e93416e4ef23f5bca3532cc Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Wed, 15 Jan 2025 10:10:45 -0600 Subject: [PATCH 20/23] Remove H5Tdecode wrapper --- fortran/src/H5Tf.c | 42 ---------------------------------------- fortran/src/H5Tff.F90 | 27 +++++++++++++++----------- fortran/src/H5f90proto.h | 1 - 3 files changed, 16 insertions(+), 54 deletions(-) diff --git a/fortran/src/H5Tf.c b/fortran/src/H5Tf.c index 58cc0e1321d..1c61cac273a 100644 --- a/fortran/src/H5Tf.c +++ b/fortran/src/H5Tf.c @@ -1890,48 +1890,6 @@ h5tcommitted_c(hid_t_f *dtype_id) return ret_value; } -/****if* H5Tf/h5tdecode_c - * NAME - * h5tdecode_c - * PURPOSE - * Call H5Tdecode - * INPUTS - * - * buf - Buffer for the data space object to be decoded. - * buf_size - Size of the buffer - * OUTPUTS - * - * obj_id - Object_id (non-negative) - * - * RETURNS - * 0 on success, -1 on failure - * SOURCE - */ - -int_f -h5tdecode_c(_fcd buf, size_t_f buf_size, hid_t_f *obj_id) -/******/ -{ - int ret_value = -1; - unsigned char *c_buf = NULL; /* Buffer to hold C string */ - hid_t c_obj_id; - - /* - * Call H5Tdecode function. - */ - - c_buf = (unsigned char *)buf; - - c_obj_id = H5Tdecode2(c_buf, buf_size); - if (c_obj_id < 0) - return ret_value; - - *obj_id = (hid_t_f)c_obj_id; - ret_value = 0; - - return ret_value; -} - /****if* H5Tf/h5tencode_c * NAME * h5tencode_c diff --git a/fortran/src/H5Tff.F90 b/fortran/src/H5Tff.F90 index ec80977e19f..33644b10f39 100644 --- a/fortran/src/H5Tff.F90 +++ b/fortran/src/H5Tff.F90 @@ -1876,19 +1876,22 @@ SUBROUTINE h5tdecode_with_size_f(buf, buf_size, obj_id, hdferr) INTEGER(HID_T), INTENT(OUT) :: obj_id INTEGER, INTENT(OUT) :: hdferr INTERFACE - INTEGER FUNCTION h5tdecode_c(buf, buf_size, obj_id) BIND(C,NAME='h5tdecode_c') + INTEGER(HID_T) FUNCTION H5Tdecode2(buf, buf_size) BIND(C,NAME='H5Tdecode2') IMPORT :: C_CHAR IMPORT :: HID_T, SIZE_T IMPLICIT NONE CHARACTER(KIND=C_CHAR), DIMENSION(*), INTENT(IN) :: buf INTEGER(SIZE_T), INTENT(IN) :: buf_size - INTEGER(HID_T), INTENT(OUT) :: obj_id - END FUNCTION h5tdecode_c + END FUNCTION H5Tdecode2 END INTERFACE - hdferr = h5tdecode_c(buf, buf_size, obj_id) -END SUBROUTINE h5tdecode_with_size_f + obj_id = H5Tdecode2(buf, buf_size) + + IF(obj_id.LT.0)THEN + hdferr = -1 + ENDIF +END SUBROUTINE h5tdecode_with_size_f !> !! \ingroup FH5T !! @@ -1907,21 +1910,23 @@ SUBROUTINE h5tdecode_auto_size_f(buf, obj_id, hdferr) INTEGER, INTENT(OUT) :: hdferr INTEGER(SIZE_T) :: buf_size INTERFACE - INTEGER FUNCTION h5tdecode_c(buf, buf_size, obj_id) BIND(C,NAME='h5tdecode_c') + INTEGER(HID_T) FUNCTION H5Tdecode2(buf, buf_size) BIND(C,NAME='H5Tdecode2') IMPORT :: C_CHAR IMPORT :: HID_T, SIZE_T IMPLICIT NONE CHARACTER(KIND=C_CHAR), DIMENSION(*), INTENT(IN) :: buf INTEGER(SIZE_T), INTENT(IN) :: buf_size - INTEGER(HID_T), INTENT(OUT) :: obj_id - END FUNCTION h5tdecode_c + END FUNCTION H5Tdecode2 END INTERFACE buf_size = LEN(buf) - hdferr = h5tdecode_c(buf, buf_size, obj_id) -END SUBROUTINE h5tdecode_auto_size_f + obj_id = H5Tdecode2(buf, buf_size) -!> + IF(obj_id.LT.0)THEN + hdferr = -1 + ENDIF + +END SUBROUTINE h5tdecode_auto_size_f!> !! \ingroup FH5T !! !! \brief Encode a data type object description into a binary buffer. diff --git a/fortran/src/H5f90proto.h b/fortran/src/H5f90proto.h index 60d4b1c5b6c..5096cbcfbab 100644 --- a/fortran/src/H5f90proto.h +++ b/fortran/src/H5f90proto.h @@ -327,7 +327,6 @@ H5_FCDLL int_f h5tvlen_create_c(hid_t_f *type_id, hid_t_f *vltype_id); H5_FCDLL int_f h5tis_variable_str_c(hid_t_f *type_id, int_f *flag); H5_FCDLL int_f h5tget_member_class_c(hid_t_f *type_id, int_f *member_no, int_f *cls); H5_FCDLL int_f h5tcommit_anon_c(hid_t_f *loc_id, hid_t_f *dtype_id, hid_t_f *tcpl_id, hid_t_f *tapl_id); -H5_FCDLL int_f h5tdecode_c(_fcd buf, size_t_f buf_size, hid_t_f *obj_id); H5_FCDLL int_f h5tencode_c(_fcd buf, hid_t_f *obj_id, size_t_f *nalloc); H5_FCDLL int_f h5tget_create_plist_c(hid_t_f *dtype_id, hid_t_f *dtpl_id); H5_FCDLL int_f h5tcompiler_conv_c(hid_t_f *src_id, hid_t_f *dst_id, int_f *c_flag); From 189d61dbd378372dfac5867704a636e40f929522 Mon Sep 17 00:00:00 2001 From: Scot Breitenfeld Date: Thu, 23 Jan 2025 15:40:16 -0600 Subject: [PATCH 21/23] Update H5Tff.F90 Make buf_size an optional a parameter --- fortran/src/H5Tff.F90 | 63 ++++++++++++------------------------------- 1 file changed, 17 insertions(+), 46 deletions(-) diff --git a/fortran/src/H5Tff.F90 b/fortran/src/H5Tff.F90 index 33644b10f39..4e2c2d93c51 100644 --- a/fortran/src/H5Tff.F90 +++ b/fortran/src/H5Tff.F90 @@ -58,11 +58,6 @@ MODULE H5T #endif -INTERFACE h5tdecode_f - MODULE PROCEDURE h5tdecode_with_size_f - MODULE PROCEDURE h5tdecode_auto_size_f -END INTERFACE h5tdecode_f - CONTAINS !> @@ -1860,73 +1855,49 @@ END SUBROUTINE h5tcommitted_f !> !! \ingroup FH5T !! -!! \brief Decode A binary object description of data type and return a new object handle. +!! \brief Decode a binary object description of data type and return a new object handle. !! !! \param buf Buffer for the data space object to be decoded. -!! \param buf_size Size of the buffer. !! \param obj_id Object ID. !! \param hdferr \fortran_error +!! \param buf_size Size of the buffer. !! !! See C API: @ref H5Tdecode2() !! -SUBROUTINE h5tdecode_with_size_f(buf, buf_size, obj_id, hdferr) +SUBROUTINE h5tdecode_f(buf, obj_id, hdferr, buf_size) IMPLICIT NONE CHARACTER(LEN=*), INTENT(IN) :: buf - INTEGER(SIZE_T), INTENT(IN) :: buf_size INTEGER(HID_T), INTENT(OUT) :: obj_id INTEGER, INTENT(OUT) :: hdferr - INTERFACE - INTEGER(HID_T) FUNCTION H5Tdecode2(buf, buf_size) BIND(C,NAME='H5Tdecode2') - IMPORT :: C_CHAR - IMPORT :: HID_T, SIZE_T - IMPLICIT NONE - CHARACTER(KIND=C_CHAR), DIMENSION(*), INTENT(IN) :: buf - INTEGER(SIZE_T), INTENT(IN) :: buf_size - END FUNCTION H5Tdecode2 - END INTERFACE - - obj_id = H5Tdecode2(buf, buf_size) + INTEGER(SIZE_T), OPTIONAL, INTENT(IN) :: buf_size - IF(obj_id.LT.0)THEN - hdferr = -1 - ENDIF + INTEGER(SIZE_T) :: buf_size_default -END SUBROUTINE h5tdecode_with_size_f -!> -!! \ingroup FH5T -!! -!! \brief Decode A binary object description of data type and return a new object handle. -!! -!! \param buf Buffer for the data space object to be decoded. -!! \param obj_id Object ID. -!! \param hdferr \fortran_error -!! -!! See C API: @ref H5Tdecode2() -!! -SUBROUTINE h5tdecode_auto_size_f(buf, obj_id, hdferr) - IMPLICIT NONE - CHARACTER(LEN=*), INTENT(IN) :: buf - INTEGER(HID_T), INTENT(OUT) :: obj_id - INTEGER, INTENT(OUT) :: hdferr - INTEGER(SIZE_T) :: buf_size INTERFACE INTEGER(HID_T) FUNCTION H5Tdecode2(buf, buf_size) BIND(C,NAME='H5Tdecode2') IMPORT :: C_CHAR IMPORT :: HID_T, SIZE_T IMPLICIT NONE - CHARACTER(KIND=C_CHAR), DIMENSION(*), INTENT(IN) :: buf - INTEGER(SIZE_T), INTENT(IN) :: buf_size + CHARACTER(KIND=C_CHAR), DIMENSION(*) :: buf + INTEGER(SIZE_T), VALUE :: buf_size END FUNCTION H5Tdecode2 END INTERFACE - buf_size = LEN(buf) - obj_id = H5Tdecode2(buf, buf_size) + IF(PRESENT(buf_size))THEN + buf_size_default = buf_size + ELSE + buf_size_default = LEN(buf) + ENDIF + + obj_id = H5Tdecode2(buf, buf_size_default) IF(obj_id.LT.0)THEN hdferr = -1 ENDIF -END SUBROUTINE h5tdecode_auto_size_f!> +END SUBROUTINE h5tdecode_f + +!> !! \ingroup FH5T !! !! \brief Encode a data type object description into a binary buffer. From a026ad5a1ed69a23be61b86226af15259bec117f Mon Sep 17 00:00:00 2001 From: Scot Breitenfeld Date: Thu, 23 Jan 2025 15:42:09 -0600 Subject: [PATCH 22/23] Update hdf5_fortrandll.def.in Make buf_size optional --- fortran/src/hdf5_fortrandll.def.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fortran/src/hdf5_fortrandll.def.in b/fortran/src/hdf5_fortrandll.def.in index d7b9b8a46de..5bc4a274c42 100644 --- a/fortran/src/hdf5_fortrandll.def.in +++ b/fortran/src/hdf5_fortrandll.def.in @@ -575,8 +575,7 @@ H5T_mp_H5TIS_VARIABLE_STR_F H5T_mp_H5TGET_MEMBER_CLASS_F H5T_mp_H5TCOMMIT_ANON_F H5T_mp_H5TCOMMITTED_F -H5T_mp_H5TDECODE_WITH_SIZE_F -H5T_mp_H5TDECODE_AUTO_SIZE_F +H5T_mp_H5TDECODE_F H5T_mp_H5TENCODE_F H5T_mp_H5TGET_CREATE_PLIST_F H5T_mp_H5TCOMPILER_CONV_F From c4644a6d5135516a94f80ef0a8fea1f296f0b591 Mon Sep 17 00:00:00 2001 From: Scot Breitenfeld Date: Thu, 23 Jan 2025 15:53:57 -0600 Subject: [PATCH 23/23] Update tH5T.F90 test optional parameter --- fortran/test/tH5T.F90 | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fortran/test/tH5T.F90 b/fortran/test/tH5T.F90 index ae131cf16e7..6424230cdd4 100644 --- a/fortran/test/tH5T.F90 +++ b/fortran/test/tH5T.F90 @@ -554,13 +554,11 @@ SUBROUTINE compoundtest(cleanup, total_error) CALL H5Tencode_f(dtype_id, cmpd_buf, cmpd_buf_size, error) CALL check("H5Tencode_f", error, total_error) - ! Try decoding bogus buffer + ! Try decoding bogus buffer with and without optional buffer size - CALL H5Tdecode_f(cmpd_buf, cmpd_buf_size, decoded_tid1, error) + CALL H5Tdecode_f(cmpd_buf, decoded_tid1, error, cmpd_buf_size) CALL verify("H5Tdecode_f", error, -1, total_error) - ! Try decoding bogus buffer with automatic size detection - CALL H5Tdecode_f(cmpd_buf, decoded_tid1, error) CALL verify("H5Tdecode_f", error, -1, total_error) @@ -568,7 +566,7 @@ SUBROUTINE compoundtest(cleanup, total_error) CALL check("H5Tencode_f", error, total_error) ! Decode from the compound buffer and return an object handle - CALL H5Tdecode_f(cmpd_buf, cmpd_buf_size, decoded_tid1, error) + CALL H5Tdecode_f(cmpd_buf, decoded_tid1, error, cmpd_buf_size) CALL check("H5Tdecode_f", error, total_error) ! Verify that the datatype was copied exactly @@ -577,7 +575,7 @@ SUBROUTINE compoundtest(cleanup, total_error) CALL check("H5Tequal_f", error, total_error) CALL verify("H5Tequal_f", flag, .TRUE., total_error) - ! Decode from the compound buffer with automatic size detection + ! Decode from the compound buffer without the optional parameter CALL H5Tdecode_f(cmpd_buf, decoded_tid2, error) CALL check("H5Tdecode_f", error, total_error)