diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2005-06-14 21:29:58 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2005-06-14 21:29:58 (GMT) |
commit | 2b6ff9a014e1a1c79aea220c225b5b28dec0b67d (patch) | |
tree | 639013dfd54640600b23c6046ef1028597ac4e64 | |
parent | 6d5e454fddf280a2c89d6efe4ad4bc8a88532308 (diff) | |
download | hdf5-2b6ff9a014e1a1c79aea220c225b5b28dec0b67d.zip hdf5-2b6ff9a014e1a1c79aea220c225b5b28dec0b67d.tar.gz hdf5-2b6ff9a014e1a1c79aea220c225b5b28dec0b67d.tar.bz2 |
[svn-r10922] Purpose:
Bug fix
Description:
Add check for opaque tags that are too long for file format to handle
currently.
Platforms tested:
FreeBSD 4.11 (sleipnir)
Too minor to require h5commmitest
-rw-r--r-- | src/H5Odtype.c | 6 | ||||
-rw-r--r-- | src/H5Topaque.c | 2 | ||||
-rw-r--r-- | src/H5Tpublic.h | 4 | ||||
-rw-r--r-- | test/dtypes.c | 56 |
4 files changed, 65 insertions, 3 deletions
diff --git a/src/H5Odtype.c b/src/H5Odtype.c index d627ac3..604bbb0 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -136,7 +136,7 @@ H5O_dtype_decode_helper(H5F_t *f, const uint8_t **pp, H5T_t *dt) /* * Opaque types... */ - z = flags & 0xff; + z = flags & (H5T_OPAQUE_TAG_MAX - 1); assert(0==(z&0x7)); /*must be aligned*/ if (NULL==(dt->shared->u.opaque.tag=H5MM_malloc(z+1))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); @@ -576,7 +576,7 @@ H5O_dtype_encode_helper(uint8_t **pp, const H5T_t *dt) * null terminated). */ z = HDstrlen(dt->shared->u.opaque.tag); - aligned = (z+7) & 0xf8; + aligned = (z+7) & (H5T_OPAQUE_TAG_MAX - 8); flags |= aligned; HDmemcpy(*pp, dt->shared->u.opaque.tag, MIN(z,aligned)); for (n=MIN(z,aligned); n<aligned; n++) (*pp)[n] = 0; @@ -995,7 +995,7 @@ H5O_dtype_size(const H5F_t *f, const void *mesg) break; case H5T_OPAQUE: - ret_value += (HDstrlen(dt->shared->u.opaque.tag)+7) & 0xf8; + ret_value += (HDstrlen(dt->shared->u.opaque.tag)+7) & (H5T_OPAQUE_TAG_MAX - 8); break; case H5T_FLOAT: diff --git a/src/H5Topaque.c b/src/H5Topaque.c index 58535a2..0121957 100644 --- a/src/H5Topaque.c +++ b/src/H5Topaque.c @@ -86,6 +86,8 @@ H5Tset_tag(hid_t type_id, const char *tag) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an opaque data type") if (!tag) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no tag") + if (HDstrlen(tag) >= H5T_OPAQUE_TAG_MAX) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "tag too long") /* Commit */ H5MM_xfree(dt->shared->u.opaque.tag); diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index 0212fd8..4d7136f 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -177,6 +177,10 @@ typedef struct { /* Variable Length String information */ #define H5T_VARIABLE ((size_t)(-1)) /* Indicate that a string is variable length (null-terminated in C, instead of fixed length) */ +/* Opaque information */ +#define H5T_OPAQUE_TAG_MAX 256 /* Maximum length of an opaque tag */ + /* This could be raised without too much difficulty */ + #ifdef __cplusplus extern "C" { #endif diff --git a/test/dtypes.c b/test/dtypes.c index 627d6c3..7d870df 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -129,6 +129,7 @@ static herr_t convert_opaque(hid_t UNUSED st, hid_t UNUSED dt, size_t UNUSED nelmts, size_t UNUSED buf_stride, size_t UNUSED bkg_stride, void UNUSED *_buf, void UNUSED *bkg, hid_t UNUSED dset_xfer_plid); +static int opaque_long(void); /*------------------------------------------------------------------------- @@ -4106,6 +4107,8 @@ test_opaque(void) num_errors += opaque_check(0); /* Test opaque types without tag */ num_errors += opaque_check(1); + /* Test named opaque types with very long tag */ + num_errors += opaque_long(); if(num_errors) goto error; @@ -4198,6 +4201,59 @@ opaque_check(int tag_it) /*------------------------------------------------------------------------- + * Function: opaque_long + * + * Purpose: Test named (committed) opaque datatypes w/very long tags + * + * Return: Success: 0 + * + * Failure: number of errors + * + * Programmer: Quincey Koziol + * Tuesday, June 14, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +opaque_long(void) +{ + char *long_tag = NULL; + hid_t dt = -1; + herr_t ret; + + /* Build opaque type */ + if ((dt=H5Tcreate(H5T_OPAQUE, 4))<0) TEST_ERROR + + /* Create long tag */ + long_tag = HDmalloc(16384+1); + HDmemset(long_tag, 'a', 16384); + long_tag[16384] = '\0'; + + /* Set opaque type's tag */ + H5E_BEGIN_TRY { + ret = H5Tset_tag(dt, long_tag); + } H5E_END_TRY; + if(ret!=FAIL) TEST_ERROR + + /* Close datatype */ + if(H5Tclose(dt) < 0) TEST_ERROR + + /* Release memory for tag */ + HDfree(long_tag); + + return 0; + + error: + if (dt>0) H5Tclose(dt); + if (long_tag != NULL) HDfree(long_tag); + H5_FAILED(); + return 1; +} + + +/*------------------------------------------------------------------------- * Function: test_conv_int * * Purpose: Test atomic number conversions. |