diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2008-03-13 21:44:18 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2008-03-13 21:44:18 (GMT) |
commit | f331bba32c0544567dce3bdeea53211e9777b1fe (patch) | |
tree | 98352ad8795dd63a661585c00e7bb300d8277e3b /src/H5Odtype.c | |
parent | 4982e156232a6f2b5f6c66bd31d7c997a5b606bc (diff) | |
download | hdf5-f331bba32c0544567dce3bdeea53211e9777b1fe.zip hdf5-f331bba32c0544567dce3bdeea53211e9777b1fe.tar.gz hdf5-f331bba32c0544567dce3bdeea53211e9777b1fe.tar.bz2 |
[svn-r14737] Description:
Fix bug which would incorrectly encode the member offsets for compound
datatypes whose size was between 256 & 511 bytes, when the "use the latest
format" feature was enabled.
Tested on:
Mac OS X/32 10.5.2 (amazon) w/debug
FreeBSD/32 6.2 (duty) w/production
Diffstat (limited to 'src/H5Odtype.c')
-rw-r--r-- | src/H5Odtype.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/H5Odtype.c b/src/H5Odtype.c index ac07edf..ba343bc 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -232,10 +232,11 @@ H5O_dtype_decode_helper(H5F_t *f, const uint8_t **pp, H5T_t *dt) case H5T_COMPOUND: { unsigned offset_nbytes; /* Size needed to encode member offsets */ + size_t max_memb_pos = 0; /* Maximum member covered, so far */ unsigned j; /* Compute the # of bytes required to store a member offset */ - offset_nbytes = (H5V_log2_gen((uint64_t)dt->shared->size) + 7) / 8; + offset_nbytes = H5V_limit_enc_size((uint64_t)dt->shared->size); /* * Compound datatypes... @@ -336,6 +337,18 @@ H5O_dtype_decode_helper(H5F_t *f, const uint8_t **pp, H5T_t *dt) /* Set the field datatype (finally :-) */ dt->shared->u.compnd.memb[i].type = temp_type; + /* Check if this field overlaps with a prior field */ + /* (probably indicates that the file is corrupt) */ + if(i > 0 && dt->shared->u.compnd.memb[i].offset < max_memb_pos) { + for(j = 0; j < i; j++) + if(dt->shared->u.compnd.memb[i].offset >= dt->shared->u.compnd.memb[j].offset + && dt->shared->u.compnd.memb[i].offset < (dt->shared->u.compnd.memb[j].offset + dt->shared->u.compnd.memb[j].size)) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "member overlaps with previous member") + } /* end if */ + + /* Update the maximum member position covered */ + max_memb_pos = MAX(max_memb_pos, (dt->shared->u.compnd.memb[i].offset + dt->shared->u.compnd.memb[i].size)); + /* Check if the datatype stayed packed */ if(dt->shared->u.compnd.packed) { /* Check if the member type is packed */ @@ -734,7 +747,7 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) unsigned offset_nbytes; /* Size needed to encode member offsets */ /* Compute the # of bytes required to store a member offset */ - offset_nbytes = (H5V_log2_gen((uint64_t)dt->shared->size) + 7) / 8; + offset_nbytes = H5V_limit_enc_size((uint64_t)dt->shared->size); /* * Compound datatypes... @@ -1097,7 +1110,7 @@ H5O_dtype_size(const H5F_t *f, const void *_mesg) unsigned offset_nbytes; /* Size needed to encode member offsets */ /* Compute the # of bytes required to store a member offset */ - offset_nbytes = (H5V_log2_gen((uint64_t)dt->shared->size) + 7) / 8; + offset_nbytes = H5V_limit_enc_size((uint64_t)dt->shared->size); /* Compute the total size needed to encode compound datatype */ for(u = 0; u < dt->shared->u.compnd.nmembs; u++) { |