summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorVailin Choi <vchoi@jam.ad.hdfgroup.org>2018-07-11 03:00:14 (GMT)
committerVailin Choi <vchoi@jam.ad.hdfgroup.org>2018-07-11 03:00:14 (GMT)
commitcf38292064a0c3ffc6971de31573bbd1dab25b80 (patch)
tree3de4fb27cbdf847cf18462c866b2902a61930275 /tools
parent832aced6c17f40ae19eab2e8e8ca47e1fb304688 (diff)
downloadhdf5-cf38292064a0c3ffc6971de31573bbd1dab25b80.zip
hdf5-cf38292064a0c3ffc6971de31573bbd1dab25b80.tar.gz
hdf5-cf38292064a0c3ffc6971de31573bbd1dab25b80.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')
-rw-r--r--tools/src/h5stat/h5stat.c290
-rw-r--r--tools/test/h5dump/h5dumpgentest.c86
-rw-r--r--tools/test/h5dump/testh5dump.sh.in5
-rw-r--r--tools/test/h5stat/h5stat_gentest.c142
-rw-r--r--tools/test/h5stat/testfiles/h5stat_err_old_fill.ddl2
-rw-r--r--tools/test/h5stat/testfiles/h5stat_err_old_fill.h5bin0 -> 2068 bytes
-rw-r--r--tools/test/h5stat/testfiles/h5stat_err_old_layout.ddl2
-rw-r--r--tools/test/h5stat/testfiles/h5stat_err_old_layout.h5bin0 -> 2088 bytes
-rw-r--r--tools/test/h5stat/testfiles/h5stat_err_refcount.ddl2
-rw-r--r--tools/test/h5stat/testfiles/h5stat_err_refcount.h5bin0 -> 4640 bytes
-rw-r--r--tools/test/h5stat/testfiles/h5stat_help1.ddl1
-rw-r--r--tools/test/h5stat/testfiles/h5stat_help2.ddl1
-rw-r--r--tools/test/h5stat/testfiles/h5stat_nofile.ddl1
-rw-r--r--tools/test/h5stat/testh5stat.sh.in15
-rw-r--r--tools/testfiles/err_attr_dspace.ddl5
-rw-r--r--tools/testfiles/err_attr_dspace.h5bin0 -> 3047 bytes
16 files changed, 420 insertions, 132 deletions
diff --git a/tools/src/h5stat/h5stat.c b/tools/src/h5stat/h5stat.c
index da713ac..ff67cf1 100644
--- a/tools/src/h5stat/h5stat.c
+++ b/tools/src/h5stat/h5stat.c
@@ -146,7 +146,7 @@ struct handler_t {
char **obj;
};
-static const char *s_opts ="Aa:Ddm:FfhGgl:sSTO:V";
+static const char *s_opts ="Aa:Ddm:EFfhGgl:sSTO:V";
/* e.g. "filemetadata" has to precede "file"; "groupmetadata" has to precede "group" etc. */
static struct long_options l_opts[] = {
{"help", no_arg, 'h'},
@@ -224,6 +224,7 @@ static struct long_options l_opts[] = {
{ "attr", no_arg, 'A' },
{ "att", no_arg, 'A' },
{ "at", no_arg, 'A' },
+ { "enable-error-stack", no_arg, 'E' },
{ "numattrs", require_arg, 'a' },
{ "numattr", require_arg, 'a' },
{ "numatt", require_arg, 'a' },
@@ -293,6 +294,7 @@ static void usage(const char *prog)
HDfprintf(stdout, " than 0. The default threshold is 10.\n");
HDfprintf(stdout, " -s, --freespace Print free space information\n");
HDfprintf(stdout, " -S, --summary Print summary of file space information\n");
+ HDfprintf(stdout, " --enable-error-stack Prints messages from the HDF5 error stack as they occur\n");
}
@@ -378,9 +380,8 @@ attribute_stats(iter_t *iter, const H5O_info_t *oi)
*
* Purpose: Gather statistics about the group
*
- * Return: Success: 0
- *
- * Failure: -1
+ * Return: Success: 0
+ * Failure: -1
*
* Programmer: Quincey Koziol
* Tuesday, August 16, 2005
@@ -402,9 +403,9 @@ attribute_stats(iter_t *iter, const H5O_info_t *oi)
static herr_t
group_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
{
- H5G_info_t ginfo; /* Group information */
- unsigned bin; /* "bin" the number of objects falls in */
- herr_t ret;
+ H5G_info_t ginfo; /* Group information */
+ unsigned bin; /* "bin" the number of objects falls in */
+ herr_t ret_value = SUCCEED; /* Return value */
/* Gather statistics about this type of object */
iter->uniq_groups++;
@@ -414,8 +415,8 @@ group_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
iter->group_ohdr_info.free_size += oi->hdr.space.free;
/* Get group information */
- ret = H5Gget_info_by_name(iter->fid, name, &ginfo, H5P_DEFAULT);
- HDassert(ret >= 0);
+ if((ret_value = H5Gget_info_by_name(iter->fid, name, &ginfo, H5P_DEFAULT)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gget_info_by_name() failed");
/* Update link stats */
/* Collect statistics for small groups */
@@ -429,10 +430,10 @@ group_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
bin = ceil_log10((unsigned long)ginfo.nlinks);
if((bin + 1) > iter->group_nbins) {
/* Allocate more storage for info about dataset's datatype */
- iter->group_bins = (unsigned long *)HDrealloc(iter->group_bins, (bin + 1) * sizeof(unsigned long));
- HDassert(iter->group_bins);
+ if((iter->group_bins = (unsigned long *)HDrealloc(iter->group_bins, (bin + 1) * sizeof(unsigned long))) == NULL)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Drealloc() failed");
- /* Initialize counts for intermediate bins */
+ /* Initialize counts for intermediate bins */
while(iter->group_nbins < bin)
iter->group_bins[iter->group_nbins++] = 0;
iter->group_nbins++;
@@ -448,10 +449,11 @@ group_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
iter->groups_heap_storage_size += oi->meta_size.obj.heap_size;
/* Update attribute metadata info */
- ret = attribute_stats(iter, oi);
- HDassert(ret >= 0);
+ if((ret_value = attribute_stats(iter, oi)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "attribute_stats failed");
- return 0;
+done:
+ return ret_value;
} /* end group_stats() */
@@ -461,7 +463,6 @@ group_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
* Purpose: Gather statistics about the dataset
*
* Return: Success: 0
- *
* Failure: -1
*
* Programmer: Quincey Koziol
@@ -472,22 +473,22 @@ group_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
static herr_t
dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
{
- unsigned bin; /* "bin" the number of objects falls in */
- hid_t did; /* Dataset ID */
- hid_t sid; /* Dataspace ID */
- hid_t tid; /* Datatype ID */
- hid_t dcpl; /* Dataset creation property list ID */
- hsize_t dims[H5S_MAX_RANK];/* Dimensions of dataset */
- H5D_layout_t lout; /* Layout of dataset */
- unsigned type_found; /* Whether the dataset's datatype was */
- /* already found */
- int ndims; /* Number of dimensions of dataset */
- hsize_t storage; /* Size of dataset storage */
- unsigned u; /* Local index variable */
- int num_ext; /* Number of external files for a dataset */
- int nfltr; /* Number of filters for a dataset */
- H5Z_filter_t fltr; /* Filter identifier */
- herr_t ret;
+ unsigned bin; /* "bin" the number of objects falls in */
+ hid_t did; /* Dataset ID */
+ hid_t sid; /* Dataspace ID */
+ hid_t tid; /* Datatype ID */
+ hid_t dcpl; /* Dataset creation property list ID */
+ hsize_t dims[H5S_MAX_RANK]; /* Dimensions of dataset */
+ H5D_layout_t lout; /* Layout of dataset */
+ unsigned type_found; /* Whether the dataset's datatype was */
+ /* already found */
+ int ndims; /* Number of dimensions of dataset */
+ hsize_t storage; /* Size of dataset storage */
+ unsigned u; /* Local index variable */
+ int num_ext; /* Number of external files for a dataset */
+ int nfltr; /* Number of filters for a dataset */
+ H5Z_filter_t fltr; /* Filter identifier */
+ herr_t ret_value = SUCCEED; /* Return value */
/* Gather statistics about this type of object */
iter->uniq_dsets++;
@@ -496,26 +497,27 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
iter->dset_ohdr_info.total_size += oi->hdr.space.total;
iter->dset_ohdr_info.free_size += oi->hdr.space.free;
- did = H5Dopen2(iter->fid, name, H5P_DEFAULT);
- HDassert(did > 0);
+ if((did = H5Dopen2(iter->fid, name, H5P_DEFAULT)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen() failed");
/* Update dataset metadata info */
iter->datasets_index_storage_size += oi->meta_size.obj.index_size;
iter->datasets_heap_storage_size += oi->meta_size.obj.heap_size;
/* Update attribute metadata info */
- ret = attribute_stats(iter, oi);
- HDassert(ret >= 0);
+ if((ret_value = attribute_stats(iter, oi)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "attribute_stats() failed");
/* Get storage info */
- storage = H5Dget_storage_size(did);
+ if((storage = H5Dget_storage_size(did)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_storage_size() failed");
/* Gather layout statistics */
- dcpl = H5Dget_create_plist(did);
- HDassert(dcpl > 0);
+ if((dcpl = H5Dget_create_plist(did)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist() failed");
- lout = H5Pget_layout(dcpl);
- HDassert(lout >= 0);
+ if((lout = H5Pget_layout(dcpl)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pget_layout() failed");
/* Object header's total size for H5D_COMPACT layout includes raw data size */
/* "storage" also includes H5D_COMPACT raw data size */
@@ -526,8 +528,8 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
(iter->dset_layouts[lout])++;
/* Get the number of external files for the dataset */
- num_ext = H5Pget_external_count(dcpl);
- assert (num_ext >= 0);
+ if((num_ext = H5Pget_external_count(dcpl)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pget_external_count() failed");
/* Accumulate raw data size accordingly */
if(num_ext) {
@@ -537,11 +539,11 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
iter->dset_storage_size += storage;
/* Gather dataspace statistics */
- sid = H5Dget_space(did);
- HDassert(sid > 0);
+ if((sid = H5Dget_space(did)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_space() failed");
- ndims = H5Sget_simple_extent_dims(sid, dims, NULL);
- HDassert(ndims >= 0);
+ if((ndims = H5Sget_simple_extent_dims(sid, dims, NULL)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims() failed");
/* Check for larger rank of dataset */
if((unsigned)ndims > iter->max_dset_rank)
@@ -552,38 +554,38 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
/* Only gather dim size statistics on 1-D datasets */
if(ndims == 1) {
- /* Determine maximum dimension size */
- if(dims[0] > iter->max_dset_dims)
- iter->max_dset_dims = dims[0];
- /* Collect statistics for small datasets */
- if(dims[0] < (hsize_t)sdsets_threshold)
- (iter->small_dset_dims[(size_t)dims[0]])++;
-
- /* Add dim count to proper bin */
- bin = ceil_log10((unsigned long)dims[0]);
- if((bin + 1) > iter->dset_dim_nbins) {
- /* Allocate more storage for info about dataset's datatype */
- iter->dset_dim_bins = (unsigned long *)HDrealloc(iter->dset_dim_bins, (bin + 1) * sizeof(unsigned long));
- HDassert(iter->dset_dim_bins);
-
- /* Initialize counts for intermediate bins */
- while(iter->dset_dim_nbins < bin)
- iter->dset_dim_bins[iter->dset_dim_nbins++] = 0;
- iter->dset_dim_nbins++;
-
- /* Initialize count for this bin */
- iter->dset_dim_bins[bin] = 1;
+ /* Determine maximum dimension size */
+ if(dims[0] > iter->max_dset_dims)
+ iter->max_dset_dims = dims[0];
+ /* Collect statistics for small datasets */
+ if(dims[0] < (hsize_t)sdsets_threshold)
+ (iter->small_dset_dims[(size_t)dims[0]])++;
+
+ /* Add dim count to proper bin */
+ bin = ceil_log10((unsigned long)dims[0]);
+ if((bin + 1) > iter->dset_dim_nbins) {
+ /* Allocate more storage for info about dataset's datatype */
+ if((iter->dset_dim_bins = (unsigned long *)HDrealloc(iter->dset_dim_bins, (bin + 1) * sizeof(unsigned long))) == NULL)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Drealloc() failed");
+
+ /* Initialize counts for intermediate bins */
+ while(iter->dset_dim_nbins < bin)
+ iter->dset_dim_bins[iter->dset_dim_nbins++] = 0;
+ iter->dset_dim_nbins++;
+
+ /* Initialize count for this bin */
+ iter->dset_dim_bins[bin] = 1;
} /* end if */
else
(iter->dset_dim_bins[bin])++;
} /* end if */
- ret = H5Sclose(sid);
- HDassert(ret >= 0);
+ if(H5Sclose(sid) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose() failed");
/* Gather datatype statistics */
- tid = H5Dget_type(did);
- HDassert(tid > 0);
+ if((tid = H5Dget_type(did)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type() failed");
type_found = FALSE;
for(u = 0; u < iter->dset_ntypes; u++)
@@ -591,6 +593,7 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
type_found = TRUE;
break;
} /* end for */
+
if(type_found)
(iter->dset_type_info[u].count)++;
else {
@@ -600,12 +603,12 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
iter->dset_ntypes++;
/* Allocate more storage for info about dataset's datatype */
- iter->dset_type_info = (dtype_info_t *)HDrealloc(iter->dset_type_info, iter->dset_ntypes * sizeof(dtype_info_t));
- HDassert(iter->dset_type_info);
+ if((iter->dset_type_info = (dtype_info_t *)HDrealloc(iter->dset_type_info, iter->dset_ntypes * sizeof(dtype_info_t))) == NULL)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Drealloc() failed");
/* Initialize information about datatype */
- iter->dset_type_info[curr_ntype].tid = H5Tcopy(tid);
- HDassert(iter->dset_type_info[curr_ntype].tid > 0);
+ if((iter->dset_type_info[curr_ntype].tid = H5Tcopy(tid)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tcopy() failed");
iter->dset_type_info[curr_ntype].count = 1;
iter->dset_type_info[curr_ntype].named = 0;
@@ -617,8 +620,8 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
if(H5Tcommitted(tid) > 0)
(iter->dset_type_info[u].named)++;
- ret = H5Tclose(tid);
- HDassert(ret >= 0);
+ if(H5Tclose(tid) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose() failed");
/* Track different filters */
if((nfltr = H5Pget_nfilters(dcpl)) >= 0) {
@@ -635,13 +638,14 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
} /* end for */
} /* endif nfltr */
- ret = H5Pclose(dcpl);
- HDassert(ret >= 0);
+ if(H5Pclose(dcpl) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose() failed");
- ret = H5Dclose(did);
- HDassert(ret >= 0);
+ if(H5Dclose(did) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose() failed");
- return 0;
+done:
+ return ret_value;
} /* end dataset_stats() */
@@ -660,7 +664,7 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
static herr_t
datatype_stats(iter_t *iter, const H5O_info_t *oi)
{
- herr_t ret;
+ herr_t ret_value = SUCCEED;
/* Gather statistics about this type of object */
iter->uniq_dtypes++;
@@ -670,10 +674,10 @@ datatype_stats(iter_t *iter, const H5O_info_t *oi)
iter->dtype_ohdr_info.free_size += oi->hdr.space.free;
/* Update attribute metadata info */
- ret = attribute_stats(iter, oi);
- HDassert(ret >= 0);
-
- return 0;
+ if((ret_value = attribute_stats(iter, oi)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "attribute_stats() failed");
+done:
+ return ret_value;
} /* end datatype_stats() */
@@ -695,6 +699,7 @@ obj_stats(const char *path, const H5O_info_t *oi, const char *already_visited,
void *_iter)
{
iter_t *iter = (iter_t *)_iter;
+ herr_t ret_value = SUCCEED;
/* If the object has already been seen then just return */
if(NULL == already_visited) {
@@ -704,15 +709,18 @@ obj_stats(const char *path, const H5O_info_t *oi, const char *already_visited,
switch(oi->type) {
case H5O_TYPE_GROUP:
- group_stats(iter, path, oi);
+ if(group_stats(iter, path, oi) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "group_stats failed");
break;
case H5O_TYPE_DATASET:
- dataset_stats(iter, path, oi);
+ if(dataset_stats(iter, path, oi) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "dataset_stats failed");
break;
case H5O_TYPE_NAMED_DATATYPE:
- datatype_stats(iter, oi);
+ if(datatype_stats(iter, oi) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "datatype_stats failed");
break;
case H5O_TYPE_UNKNOWN:
@@ -724,7 +732,8 @@ obj_stats(const char *path, const H5O_info_t *oi, const char *already_visited,
} /* end switch */
} /* end if */
- return 0;
+done:
+ return ret_value;
} /* end obj_stats() */
@@ -733,9 +742,8 @@ obj_stats(const char *path, const H5O_info_t *oi, const char *already_visited,
*
* Purpose: Gather statistics about a link
*
- * Return: Success: 0
- *
- * Failure: -1
+ * Return: Success: 0
+ * Failure: -1
*
* Programmer: Quincey Koziol
* Tuesday, November 6, 2007
@@ -892,6 +900,10 @@ parse_command_line(int argc, const char *argv[], struct handler_t **hand_ret)
goto done;
break;
+ case 'E':
+ enable_error_stack = 1;
+ break;
+
case 'F':
display_all = FALSE;
display_file_metadata = TRUE;
@@ -913,14 +925,14 @@ parse_command_line(int argc, const char *argv[], struct handler_t **hand_ret)
break;
case 'l':
- if(opt_arg) {
- sgroups_threshold = HDatoi(opt_arg);
- if(sgroups_threshold < 1) {
- error_msg("Invalid threshold for small groups\n");
- goto error;
- }
- } else
- error_msg("Missing threshold for small groups\n");
+ if(opt_arg) {
+ sgroups_threshold = HDatoi(opt_arg);
+ if(sgroups_threshold < 1) {
+ error_msg("Invalid threshold for small groups\n");
+ goto error;
+ }
+ } else
+ error_msg("Missing threshold for small groups\n");
break;
@@ -935,14 +947,14 @@ parse_command_line(int argc, const char *argv[], struct handler_t **hand_ret)
break;
case 'm':
- if(opt_arg) {
- sdsets_threshold = HDatoi(opt_arg);
- if(sdsets_threshold < 1) {
- error_msg("Invalid threshold for small datasets\n");
- goto error;
- }
- } else
- error_msg("Missing threshold for small datasets\n");
+ if(opt_arg) {
+ sdsets_threshold = HDatoi(opt_arg);
+ if(sdsets_threshold < 1) {
+ error_msg("Invalid threshold for small datasets\n");
+ goto error;
+ }
+ } else
+ error_msg("Missing threshold for small datasets\n");
break;
@@ -957,13 +969,13 @@ parse_command_line(int argc, const char *argv[], struct handler_t **hand_ret)
break;
case 'a':
- if(opt_arg) {
- sattrs_threshold = HDatoi(opt_arg);
- if(sattrs_threshold < 1) {
- error_msg("Invalid threshold for small # of attributes\n");
- goto error;
- }
- } else
+ if(opt_arg) {
+ sattrs_threshold = HDatoi(opt_arg);
+ if(sattrs_threshold < 1) {
+ error_msg("Invalid threshold for small # of attributes\n");
+ goto error;
+ }
+ } else
error_msg("Missing threshold for small # of attributes\n");
break;
@@ -1249,9 +1261,8 @@ print_group_info(const iter_t *iter)
*
* Purpose: Prints file space information for groups' metadata
*
- * Return: Success: 0
- *
- * Failure: Never fails
+ * Return: Success: 0
+ * Failure: Never fails
*
* Programmer: Vailin Choi; October 2009
*
@@ -1277,9 +1288,8 @@ print_group_metadata(const iter_t *iter)
*
* Purpose: Prints information about datasets in the file
*
- * Return: Success: 0
- *
- * Failure: Never fails
+ * Return: Success: 0
+ * Failure: Never fails
*
* Programmer: Elena Pourmal
* Saturday, August 12, 2006
@@ -1340,7 +1350,7 @@ print_dataset_info(const iter_t *iter)
printf("Dataset layout information:\n");
for(u = 0; u < H5D_NLAYOUTS; u++)
- printf("\tDataset layout counts[%s]: %lu\n", (u == H5D_COMPACT ? "COMPACT" :
+ printf("\tDataset layout counts[%s]: %lu\n", (u == H5D_COMPACT ? "COMPACT" :
(u == H5D_CONTIGUOUS ? "CONTIG" : (u == H5D_CHUNKED ? "CHUNKED" : "VIRTUAL"))), iter->dset_layouts[u]);
printf("\tNumber of external files : %lu\n", iter->nexternal);
@@ -1704,16 +1714,25 @@ main(int argc, const char *argv[])
iter_t iter;
const char *fname = NULL;
hid_t fid = -1;
+ H5E_auto2_t func;
+ H5E_auto2_t tools_func;
+ void *edata;
+ void *tools_edata;
struct handler_t *hand = NULL;
h5tools_setprogname(PROGRAMNAME);
h5tools_setstatus(EXIT_SUCCESS);
/* Disable error reporting */
+ H5Eget_auto2(H5E_DEFAULT, &func, &edata);
H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
/* Initialize h5tools lib */
h5tools_init();
+
+ /* Disable tools error reporting */
+ H5Eget_auto2(H5tools_ERR_STACK_g, &tools_func, &tools_edata);
+ H5Eset_auto2(H5tools_ERR_STACK_g, NULL, NULL);
HDmemset(&iter, 0, sizeof(iter));
@@ -1722,6 +1741,11 @@ main(int argc, const char *argv[])
fname = argv[opt_ind];
+ if(enable_error_stack > 0) {
+ H5Eset_auto2(H5E_DEFAULT, func, edata);
+ H5Eset_auto2(H5tools_ERR_STACK_g, tools_func, tools_edata);
+ }
+
/* Check for filename given */
if(fname) {
hid_t fcpl;
@@ -1788,16 +1812,18 @@ main(int argc, const char *argv[])
unsigned u;
for(u = 0; u < hand->obj_count; u++) {
- if(h5trav_visit(fid, hand->obj[u], TRUE, TRUE, obj_stats, lnk_stats, &iter, H5O_INFO_ALL) < 0)
- warn_msg("Unable to traverse object \"%s\"\n", hand->obj[u]);
- else
+ if(h5trav_visit(fid, hand->obj[u], TRUE, TRUE, obj_stats, lnk_stats, &iter, H5O_INFO_ALL) < 0) {
+ error_msg("unable to traverse object \"%s\"\n", hand->obj[u]);
+ h5tools_setstatus(EXIT_FAILURE);
+ } else
print_statistics(hand->obj[u], &iter);
} /* end for */
} /* end if */
else {
- if(h5trav_visit(fid, "/", TRUE, TRUE, obj_stats, lnk_stats, &iter, H5O_INFO_ALL) < 0)
- warn_msg("Unable to traverse objects/links in file \"%s\"\n", fname);
- else
+ if(h5trav_visit(fid, "/", TRUE, TRUE, obj_stats, lnk_stats, &iter, H5O_INFO_ALL) < 0) {
+ error_msg("unable to traverse objects/links in file \"%s\"\n", fname);
+ h5tools_setstatus(EXIT_FAILURE);
+ } else
print_statistics("/", &iter);
} /* end else */
} /* end if */
@@ -1813,6 +1839,8 @@ done:
h5tools_setstatus(EXIT_FAILURE);
} /* end if */
+ H5Eset_auto2(H5E_DEFAULT, func, edata);
+
leave(h5tools_getstatus());
} /* end main() */
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
diff --git a/tools/test/h5stat/h5stat_gentest.c b/tools/test/h5stat/h5stat_gentest.c
index 0f696d0..01206dd 100644
--- a/tools/test/h5stat/h5stat_gentest.c
+++ b/tools/test/h5stat/h5stat_gentest.c
@@ -21,6 +21,7 @@
* of the expected output and update the corresponding *.ddl files.
*/
#include "hdf5.h"
+#include "H5private.h"
/* For gen_newgrat_file() */
#define NEWGRAT_FILE "h5stat_newgrat.h5"
@@ -43,6 +44,9 @@
#define THRES_NUM 10
#define THRES_NUM_25 25
+/* For gen_err_refcount() */
+#define ERR_REFCOUNT_FILE "h5stat_err_refcount.h5"
+
/*
* Generate HDF5 file with latest format with
* NUM_GRPS groups and NUM_ATTRS attributes for the dataset
@@ -434,6 +438,141 @@ error:
} /* gen_idx_file() */
+/*
+ * Function: gen_err_refcount_file
+ *
+ * Purpose: Create a file with a refcount message ID.
+ * Then a refcount message ID is written to a
+ * message in a version 1 object header.
+ * This will trigger the error as a version 1
+ * object header does not support a refcount message.
+ * This is to verify HDFFV-10333 that h5stat will exit
+ * gracefully when encountered error similar to
+ * H5O_refcount_decode in the jira issue.
+ *
+ */
+static void
+gen_err_refcount(const char *fname)
+{
+ hid_t fid = -1; /* File identifier */
+ hid_t fapl = -1; /* File access property list */
+ hid_t sid = -1; /* Dataspace message */
+ hid_t did = -1; /* Dataset identifier */
+ hid_t gid = -1; /* Group identifier */
+ hid_t aid1 = -1, aid2 = -1; /* Attribute identifier */
+ hid_t tid = -1; /* Datatype identifier */
+ int i, n; /* Local index variables */
+ int buf[10]; /* Data buffer */
+ hsize_t dims[1]; /* Dimension size */
+ int fd = -1; /* File descriptor */
+ unsigned short val = 22; /* The refcount message ID */
+
+ /* Initialize data buffer */
+ n = 0;
+ for(i = 0; i < 10; i++)
+ buf[i] = n++;
+
+ /* Create the file */
+ if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
+
+ /* Create a group */
+ if((gid = H5Gcreate2(fid, "group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
+
+ /* Create a committed datatype in the group */
+ if((tid = H5Tcopy(H5T_NATIVE_INT)) < 0)
+ goto error;
+ if(H5Tcommit2(gid, "dtype", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0)
+ goto error;
+
+ /* Create the dataspace */
+ dims[0] = 10;
+ if((sid = H5Screate_simple(1, dims, NULL)) < 0)
+ goto error;
+
+ /* Create a dataset with the committed datatype in the file */
+ if((did = H5Dcreate2(fid, "dset", tid, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
+ /* Write to the dataset */
+ if(H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
+ goto error;
+
+ /* Attach an attribute with the committed datatype to the group */
+ if((aid1 = H5Acreate2(gid, "attr", tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
+ /* Attach an attribute with the committed datatype to the dataset */
+ if((aid2 = H5Acreate2(did, "attr", tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
+
+ /* Closing */
+ if(H5Aclose(aid1) < 0)
+ goto error;
+ if(H5Aclose(aid2) < 0)
+ goto error;
+ if(H5Sclose(sid) < 0)
+ goto error;
+ if(H5Dclose(did) < 0)
+ goto error;
+ if(H5Gclose(gid) < 0)
+ goto error;
+ if(H5Tclose(tid) < 0)
+ goto error;
+ if(H5Fclose(fid) < 0)
+ goto error;
+
+ /* This section of code will write a refcount message ID to a message in the
+ version 1 object header which does not support a refcount message */
+ /* Offset of the message ID to modify is as follows: */
+ /* 4520: the offset of the object header containing the attribute message
+ with the committed datatype */
+ /* 24: the offset in the object header containing the version of the
+ attribute message */
+ if((fd = HDopen(fname, O_RDWR, 0633)) < 0)
+ goto error;
+ if(HDlseek(fd, 4520+24, SEEK_SET) < 0)
+ goto error;
+ if(HDwrite(fd, &val, 2) < 0)
+ goto error;
+ if(HDclose(fd) < 0)
+ goto error;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Gclose(gid);
+ H5Dclose(did);
+ H5Tclose(tid);
+ H5Sclose(sid);
+ H5Aclose(aid1);
+ H5Aclose(aid2);
+ H5Fclose(fid);
+ } H5E_END_TRY;
+} /* gen_err_refcount() */
+
+/*
+ * The following two test files are generated with older versions
+ * of the library for HDFFV-10333. They are used for testing in
+ * testh5stat.sh.in.
+ *
+ * (1) h5stat_err_old_layout.h5
+ * This file is generated with the 1.6 library so that a file
+ * with a version 2 layout message is created.
+ * Then a "0" is written to the "dimension" field in the layout
+ * message to trigger the error.
+ * This is to verify HDFFV-10333 that h5stat will exit gracefully
+ * when encountered error similar to H5O__layout_decode in the
+ * jira issue.
+ *
+ * (2) h5stat_err_old_fill.h5
+ * This file is generated with the 1.4 library so that a file
+ * with an old fill value message is created.
+ * Then an illegal size is written to the "size" fild in the
+ * fill value message to trigger the error.
+ * This is to verify HDFFV-10333 that h5stat will exit gracefully
+ * when encountered error similar to H5O_fill_old_decode in the
+ * jira issue.
+ */
+
int main(void)
{
gen_newgrat_file(NEWGRAT_FILE);
@@ -442,6 +581,9 @@ int main(void)
/* Generate an HDF file to test for datasets with Fixed Array indexing */
gen_idx_file(IDX_FILE);
+ /* Generate a file with a refcount message ID */
+ gen_err_refcount(ERR_REFCOUNT_FILE);
+
return 0;
}
diff --git a/tools/test/h5stat/testfiles/h5stat_err_old_fill.ddl b/tools/test/h5stat/testfiles/h5stat_err_old_fill.ddl
new file mode 100644
index 0000000..e751b7f
--- /dev/null
+++ b/tools/test/h5stat/testfiles/h5stat_err_old_fill.ddl
@@ -0,0 +1,2 @@
+Filename: h5stat_err_old_fill.h5
+h5stat error: unable to traverse objects/links in file "h5stat_err_old_fill.h5"
diff --git a/tools/test/h5stat/testfiles/h5stat_err_old_fill.h5 b/tools/test/h5stat/testfiles/h5stat_err_old_fill.h5
new file mode 100644
index 0000000..aa164f0
--- /dev/null
+++ b/tools/test/h5stat/testfiles/h5stat_err_old_fill.h5
Binary files differ
diff --git a/tools/test/h5stat/testfiles/h5stat_err_old_layout.ddl b/tools/test/h5stat/testfiles/h5stat_err_old_layout.ddl
new file mode 100644
index 0000000..a3e27e2
--- /dev/null
+++ b/tools/test/h5stat/testfiles/h5stat_err_old_layout.ddl
@@ -0,0 +1,2 @@
+Filename: h5stat_err_old_layout.h5
+h5stat error: unable to traverse objects/links in file "h5stat_err_old_layout.h5"
diff --git a/tools/test/h5stat/testfiles/h5stat_err_old_layout.h5 b/tools/test/h5stat/testfiles/h5stat_err_old_layout.h5
new file mode 100644
index 0000000..5c0b5dc
--- /dev/null
+++ b/tools/test/h5stat/testfiles/h5stat_err_old_layout.h5
Binary files differ
diff --git a/tools/test/h5stat/testfiles/h5stat_err_refcount.ddl b/tools/test/h5stat/testfiles/h5stat_err_refcount.ddl
new file mode 100644
index 0000000..1f1b491
--- /dev/null
+++ b/tools/test/h5stat/testfiles/h5stat_err_refcount.ddl
@@ -0,0 +1,2 @@
+Filename: h5stat_err_refcount.h5
+h5stat error: unable to traverse objects/links in file "h5stat_err_refcount.h5"
diff --git a/tools/test/h5stat/testfiles/h5stat_err_refcount.h5 b/tools/test/h5stat/testfiles/h5stat_err_refcount.h5
new file mode 100644
index 0000000..5e0d5f9
--- /dev/null
+++ b/tools/test/h5stat/testfiles/h5stat_err_refcount.h5
Binary files differ
diff --git a/tools/test/h5stat/testfiles/h5stat_help1.ddl b/tools/test/h5stat/testfiles/h5stat_help1.ddl
index d2a8715..01e39af 100644
--- a/tools/test/h5stat/testfiles/h5stat_help1.ddl
+++ b/tools/test/h5stat/testfiles/h5stat_help1.ddl
@@ -22,3 +22,4 @@ Usage: h5stat [OPTIONS] file
than 0. The default threshold is 10.
-s, --freespace Print free space information
-S, --summary Print summary of file space information
+ --enable-error-stack Prints messages from the HDF5 error stack as they occur
diff --git a/tools/test/h5stat/testfiles/h5stat_help2.ddl b/tools/test/h5stat/testfiles/h5stat_help2.ddl
index d2a8715..01e39af 100644
--- a/tools/test/h5stat/testfiles/h5stat_help2.ddl
+++ b/tools/test/h5stat/testfiles/h5stat_help2.ddl
@@ -22,3 +22,4 @@ Usage: h5stat [OPTIONS] file
than 0. The default threshold is 10.
-s, --freespace Print free space information
-S, --summary Print summary of file space information
+ --enable-error-stack Prints messages from the HDF5 error stack as they occur
diff --git a/tools/test/h5stat/testfiles/h5stat_nofile.ddl b/tools/test/h5stat/testfiles/h5stat_nofile.ddl
index d8a8b2c..7171320 100644
--- a/tools/test/h5stat/testfiles/h5stat_nofile.ddl
+++ b/tools/test/h5stat/testfiles/h5stat_nofile.ddl
@@ -22,4 +22,5 @@ Usage: h5stat [OPTIONS] file
than 0. The default threshold is 10.
-s, --freespace Print free space information
-S, --summary Print summary of file space information
+ --enable-error-stack Prints messages from the HDF5 error stack as they occur
h5stat error: missing file name
diff --git a/tools/test/h5stat/testh5stat.sh.in b/tools/test/h5stat/testh5stat.sh.in
index ca7ca4c..d178b0d 100644
--- a/tools/test/h5stat/testh5stat.sh.in
+++ b/tools/test/h5stat/testh5stat.sh.in
@@ -74,6 +74,9 @@ $SRC_H5STAT_TESTFILES/h5stat_tsohm.h5
$SRC_H5STAT_TESTFILES/h5stat_newgrat.h5
$SRC_H5STAT_TESTFILES/h5stat_idx.h5
$SRC_H5STAT_TESTFILES/h5stat_threshold.h5
+$SRC_H5STAT_TESTFILES/h5stat_err_refcount.h5
+$SRC_H5STAT_TESTFILES/h5stat_err_old_layout.h5
+$SRC_H5STAT_TESTFILES/h5stat_err_old_fill.h5
"
LIST_OTHER_TEST_FILES="
@@ -109,6 +112,9 @@ $SRC_H5STAT_TESTFILES/h5stat_numattrs1.ddl
$SRC_H5STAT_TESTFILES/h5stat_numattrs2.ddl
$SRC_H5STAT_TESTFILES/h5stat_numattrs3.ddl
$SRC_H5STAT_TESTFILES/h5stat_numattrs4.ddl
+$SRC_H5STAT_TESTFILES/h5stat_err_refcount.ddl
+$SRC_H5STAT_TESTFILES/h5stat_err_old_layout.ddl
+$SRC_H5STAT_TESTFILES/h5stat_err_old_fill.ddl
"
#
@@ -243,6 +249,7 @@ TOOLTEST h5stat_help2.ddl --help
TOOLTEST h5stat_notexist.ddl notexist.h5
TOOLTEST h5stat_nofile.ddl ''
+
# Test file with groups, compressed datasets, user-applied fileters, etc.
# h5stat_filters.h5 is a copy of ../../testfiles/tfilters.h5 as of release 1.8.0-alpha4
TOOLTEST h5stat_filters.ddl h5stat_filters.h5
@@ -304,7 +311,13 @@ TOOLTEST h5stat_numattrs3.ddl -A --numattrs=25 h5stat_threshold.h5
# -A -a 100
TOOLTEST h5stat_numattrs4.ddl -A -a 100 h5stat_newgrat.h5
#
-
+#
+# Tests to verify HDFFV-10333
+TOOLTEST h5stat_err_refcount.ddl h5stat_err_refcount.h5
+TOOLTEST h5stat_err_old_layout.ddl h5stat_err_old_layout.h5
+TOOLTEST h5stat_err_old_fill.ddl h5stat_err_old_fill.h5
+#
+#
# Clean up temporary files/directories
CLEAN_TESTFILES_AND_TESTDIR
diff --git a/tools/testfiles/err_attr_dspace.ddl b/tools/testfiles/err_attr_dspace.ddl
new file mode 100644
index 0000000..6c45322
--- /dev/null
+++ b/tools/testfiles/err_attr_dspace.ddl
@@ -0,0 +1,5 @@
+HDF5 "err_attr_dspace.h5" {
+GROUP "/" {
+}
+}
+h5dump error: error getting attribute information
diff --git a/tools/testfiles/err_attr_dspace.h5 b/tools/testfiles/err_attr_dspace.h5
new file mode 100644
index 0000000..969c328
--- /dev/null
+++ b/tools/testfiles/err_attr_dspace.h5
Binary files differ