summaryrefslogtreecommitdiffstats
path: root/tools/test/h5dump
diff options
context:
space:
mode:
authorVailin Choi <vchoi@jam.ad.hdfgroup.org>2018-07-11 03:00:14 (GMT)
committerM. Scot Breitenfeld <brtnfld@hdfgroup.org>2018-07-26 22:16:50 (GMT)
commit78d4fbddbd20904f9ee05a1d5de3ddd701453d24 (patch)
treed0f9cf6e29233f55b1e4f9f40e986de61b5872f4 /tools/test/h5dump
parent256f74f5320a5a97fc396b942c7d54331740244d (diff)
downloadhdf5-78d4fbddbd20904f9ee05a1d5de3ddd701453d24.zip
hdf5-78d4fbddbd20904f9ee05a1d5de3ddd701453d24.tar.gz
hdf5-78d4fbddbd20904f9ee05a1d5de3ddd701453d24.tar.bz2
Fix for HDFFV-10333:
1) Check for valid object header version for a refcount messge 2) Check for invalid fill value size 3) Check for invalid dimension size in a layout message 4) Add --enable-error-stack option to h5stat 5) Add error checks to h5stat.c 6) Add tests to h5stat and h5dump
Diffstat (limited to 'tools/test/h5dump')
-rw-r--r--tools/test/h5dump/h5dumpgentest.c86
-rw-r--r--tools/test/h5dump/testh5dump.sh.in5
2 files changed, 91 insertions, 0 deletions
diff --git a/tools/test/h5dump/h5dumpgentest.c b/tools/test/h5dump/h5dumpgentest.c
index 9358fbb..f34d479 100644
--- a/tools/test/h5dump/h5dumpgentest.c
+++ b/tools/test/h5dump/h5dumpgentest.c
@@ -113,6 +113,7 @@
#define FILE83 "tvlenstr_array.h5"
#define FILE84 "tudfilter.h5"
#define FILE85 "tgrpnullspace.h5"
+#define FILE86 "err_attr_dspace.h5"
/*-------------------------------------------------------------------------
* prototypes
@@ -10476,6 +10477,89 @@ static void gent_null_space_group(void)
H5Fclose(fid);
}
+/*-------------------------------------------------------------------------
+ * Function: gent_err_attr_dspace
+ *
+ * Purpose: Generate a file with shared dataspace message.
+ * Then write an illegal version to the shared dataspace message
+ * to trigger the error.
+ * This is to verify HDFFV-10333 that h5dump will exit
+ * gracefully when encountered error similar to
+ * H5O_attr_decode in the jira issue.
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+gent_err_attr_dspace()
+{
+ hid_t fid = -1; /* File identifier */
+ hid_t fcpl = -1; /* File access property list */
+ hid_t sid; /* Dataspace identifier */
+ hid_t aid; /* Attribute identifier */
+ hsize_t dims = 2; /* Dimensino size */
+ int wdata[2] = {7, 42}; /* The buffer to write */
+ int fd = -1; /* The file descriptor */
+ char val = 6; /* An invalid version */
+
+ /* Create an fcpl */
+ if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
+ goto error;
+
+ /* Set up the dataspace message to be shared */
+ if(H5Pset_shared_mesg_nindexes(fcpl, 1) < 0)
+ goto error;
+ if(H5Pset_shared_mesg_index(fcpl, 0, H5O_SHMESG_SDSPACE_FLAG, 1) < 0)
+ goto error;
+
+ /* Create the file with the shared message setting */
+ if((fid = H5Fcreate(FILE86, H5F_ACC_TRUNC, fcpl, H5P_DEFAULT)) < 0)
+ goto error;
+
+ /* Create the dataspace */
+ if((sid = H5Screate_simple(1, &dims, &dims)) < 0)
+ goto error;
+
+ /* Create an attribute with shared dataspace */
+ if((aid = H5Acreate2(fid, "attribute", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
+ if(H5Awrite(aid, H5T_NATIVE_INT, wdata) < 0)
+ goto error;
+
+ /* Closing */
+ if(H5Aclose(aid) < 0)
+ goto error;
+ if(H5Sclose(sid) < 0)
+ goto error;
+ if(H5Pclose(fcpl) < 0)
+ goto error;
+ if(H5Fclose(fid) < 0)
+ goto error;
+
+ /* This section of code will write an illegal version to the "version" field
+ of the shared dataspace message */
+ if((fd = HDopen(FILE86, O_RDWR, 0633)) < 0)
+ goto error;
+
+ /* Offset of the "version" field to modify is as follows: */
+ /* 1916: offset of the object header containing the attribute message */
+ /* 32: offset of the attribute message in the object header */
+ /* 30: offset in the attribute message containing the version of the shared dataspace message */
+ if(HDlseek(fd, 1916+32+30, SEEK_SET) < 0)
+ goto error;
+ if(HDwrite(fd, &val, 1) < 0)
+ goto error;
+ if(HDclose(fd) < 0)
+ goto error;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Pclose(fcpl);
+ H5Aclose(aid);
+ H5Sclose(sid);
+ H5Fclose(fid);
+ } H5E_END_TRY;
+} /* gen_err_attr_dspace() */
+
int main(void)
{
gent_group();
@@ -10569,6 +10653,8 @@ int main(void)
gent_udfilter();
+ gent_err_attr_dspace();
+
return 0;
}
diff --git a/tools/test/h5dump/testh5dump.sh.in b/tools/test/h5dump/testh5dump.sh.in
index 1935b0d..a2ec035 100644
--- a/tools/test/h5dump/testh5dump.sh.in
+++ b/tools/test/h5dump/testh5dump.sh.in
@@ -175,6 +175,7 @@ $SRC_H5DUMP_TESTFILES/tvldtypes5.h5
$SRC_H5DUMP_TESTFILES/tvlenstr_array.h5
$SRC_H5DUMP_TESTFILES/tvlstr.h5
$SRC_H5DUMP_TESTFILES/tvms.h5
+$SRC_H5DUMP_TESTFILES/err_attr_dspace.h5
"
LIST_OTHER_TEST_FILES="
@@ -360,6 +361,7 @@ $SRC_H5DUMP_TESTFILES/twithddlfile.exp
$SRC_H5DUMP_TESTFILES/h5dump-help.txt
$SRC_H5DUMP_TESTFILES/out3.h5import
$SRC_H5DUMP_TESTFILES/tbinregR.exp
+$SRC_H5DUMP_TESTFILES/err_attr_dspace.ddl
"
LIST_ERROR_TEST_FILES="
@@ -1322,6 +1324,9 @@ TOOLTEST tattrreg.ddl --enable-error-stack tattrreg.h5
TOOLTEST4 tattrregR.ddl --enable-error-stack -R tattrreg.h5
TOOLTEST2 tbinregR.exp --enable-error-stack -d /Dataset1 -s 0 -R -y -o tbinregR.txt tdatareg.h5
+# test to verify HDFFV-10333: error similar to H5O_attr_decode in the jira issue
+TOOLTEST err_attr_dspace.ddl err_attr_dspace.h5
+
# Clean up text output files
if test -z "$HDF5_NOCLEANUP"; then
rm -f tbinregR.txt