diff --git a/definitions/hdf5/boot.def b/definitions/hdf5/boot.def index ecb988ebd..ba6d79bae 100644 --- a/definitions/hdf5/boot.def +++ b/definitions/hdf5/boot.def @@ -1,29 +1,31 @@ # http://www.hdfgroup.org/HDF5/doc/H5.format.html#Superblock constant identifier="HDF5"; - ascii[8] signature : dump; uint8 versionNumberOfSuperblock : dump; -if(versionNumberOfSuperblock == 2) { - uint8 sizeOfOffsets : dump; - uint8 sizeOfLength : dump; - uint8 fileConsistencyFlags : dump; +if (versionNumberOfSuperblock == 0 || + versionNumberOfSuperblock == 1 || + versionNumberOfSuperblock == 2 || + versionNumberOfSuperblock == 3) +{ + uint8 sizeOfOffsets : dump; + uint8 sizeOfLength : dump; + uint8 fileConsistencyFlags : dump; - if(sizeOfOffsets == 8) { - uint64_little_endian baseAddress : dump; - uint64_little_endian superblockExtensionAddress : dump; - uint64_little_endian endOfFileAddress : dump; - uint64_little_endian rootGroupObjectHeaderAddress : dump; - } + if(sizeOfOffsets == 8) { + uint64_little_endian baseAddress : dump; + uint64_little_endian superblockExtensionAddress : dump; + uint64_little_endian endOfFileAddress : dump; + uint64_little_endian rootGroupObjectHeaderAddress : dump; + } - if(sizeOfOffsets == 4) { - uint32_little_endian baseAddress : dump; - uint32_little_endian superblockExtensionAddress : dump; - uint32_little_endian endOfFileAddress : dump; - uint32_little_endian rootGroupObjectHeaderAddress : dump; - } - - #ascii[4] superblockChecksum; + if(sizeOfOffsets == 4) { + uint32_little_endian baseAddress : dump; + uint32_little_endian superblockExtensionAddress : dump; + uint32_little_endian endOfFileAddress : dump; + uint32_little_endian rootGroupObjectHeaderAddress : dump; + } + #ascii[4] superblockChecksum; } diff --git a/src/grib_io.c b/src/grib_io.c index 88848b07a..67f36527e 100644 --- a/src/grib_io.c +++ b/src/grib_io.c @@ -491,7 +491,11 @@ static int read_HDF5_offset(reader *r, int length, unsigned long* v, unsigned ch return 0; } - +static int check_hdf5_superblock_version(unsigned char version) +{ + if (version==0 || version==1 || version==2 || version==3) return GRIB_SUCCESS; + return GRIB_INVALID_MESSAGE; +} static int read_HDF5(reader *r) { /* See: http://www.hdfgroup.org/HDF5/doc/H5.format.html#Superblock */ @@ -529,9 +533,9 @@ static int read_HDF5(reader *r) } tmp[i++] = version_of_superblock; - - if(version_of_superblock != 2) { - grib_context_log(c, GRIB_LOG_ERROR,"read_HDF5: invalid version_of_superblock: %ld, only version 2 is supported", (long)version_of_superblock); + err = check_hdf5_superblock_version(version_of_superblock); + if(err) { + grib_context_log(c, GRIB_LOG_ERROR,"read_HDF5: invalid version of superblock: %ld", (long)version_of_superblock); return GRIB_NOT_IMPLEMENTED; }