Skip to content

Commit

Permalink
Fix H5Tdecode1 failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Jan 8, 2025
1 parent b1c6e2d commit a53b1ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/H5T.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
49 changes: 33 additions & 16 deletions test/dtypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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 */

Expand Down

0 comments on commit a53b1ad

Please sign in to comment.