From dec1eced1210ba94ddecef660c41c7f84052a16f Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 31 Jul 2018 13:30:05 +0100 Subject: [PATCH] ECC-727: handle all versions of HDF5 Super Block (versions) --- definitions/hdf5/boot.def | 40 ++++++++++++++++++++------------------- src/grib_io.c | 12 ++++++++---- 2 files changed, 29 insertions(+), 23 deletions(-) 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; }