summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5Odtype.c6
-rw-r--r--src/H5Topaque.c2
-rw-r--r--src/H5Tpublic.h4
3 files changed, 9 insertions, 3 deletions
diff --git a/src/H5Odtype.c b/src/H5Odtype.c
index fe74959..02dac26 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");
@@ -585,7 +585,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;
@@ -1004,7 +1004,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 8fe400a..a6feb73 100644
--- a/src/H5Tpublic.h
+++ b/src/H5Tpublic.h
@@ -195,6 +195,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