summaryrefslogtreecommitdiffstats
path: root/src/H5Odtype.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2008-03-13 22:12:13 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2008-03-13 22:12:13 (GMT)
commitafd5021ef9dafc99fda0e47774152f4dc2e57a6f (patch)
tree8f1aec9a3037862e13a8325c5e9db3fb999bb38e /src/H5Odtype.c
parent6763f7c8824fb415493cfdb88155449c4d22d16f (diff)
downloadhdf5-afd5021ef9dafc99fda0e47774152f4dc2e57a6f.zip
hdf5-afd5021ef9dafc99fda0e47774152f4dc2e57a6f.tar.gz
hdf5-afd5021ef9dafc99fda0e47774152f4dc2e57a6f.tar.bz2
[svn-r14738] Description:
Bring r14737 back from the 1.8 branch: 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.c19
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++) {