summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Fortner <nfortne2@hdfgroup.org>2015-09-08 20:20:48 (GMT)
committerNeil Fortner <nfortne2@hdfgroup.org>2015-09-08 20:20:48 (GMT)
commite2e68ceec5260433c2dffaa3177522915705f816 (patch)
tree8854b3347b5f84f191640ce187cd2bab0ddb5451
parent64ba92a274b32f3c8fd92e7f4caaf352933048ea (diff)
downloadhdf5-e2e68ceec5260433c2dffaa3177522915705f816.zip
hdf5-e2e68ceec5260433c2dffaa3177522915705f816.tar.gz
hdf5-e2e68ceec5260433c2dffaa3177522915705f816.tar.bz2
[svn-r27700] Port r27605 from trunk to 1.8 branch.
Tested: jam, koala, ostrich (h5committest) Log from r27605: Fix potential memory error when using a dataspace that was created with H5Screate and had its extent set by H5Sextent_copy. Tested: jam, ostrich (h5committest)
-rw-r--r--release_docs/RELEASE.txt10
-rw-r--r--src/H5S.c2
-rw-r--r--test/th5s.c43
3 files changed, 52 insertions, 3 deletions
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt
index 19c3b6a..db203ca 100644
--- a/release_docs/RELEASE.txt
+++ b/release_docs/RELEASE.txt
@@ -179,8 +179,14 @@ Bug Fixes since HDF5-1.8.15
Library
-------
- -
- (XYZ - YYYY/MM/DD HDFFV-####)
+ - Fix uninitialized memory in dataspace selection code
+
+ When creating a dataspace with H5Screate and setting the extent with
+ H5Sextent_copy, the selection offset was not initialized, potentially
+ causing invalid I/O. There may be other cases where this happened.
+ MOdified library to always initialize the offset.
+
+ (NAF - 2015-09-08)
Parallel Library
diff --git a/src/H5S.c b/src/H5S.c
index 6556f2e..5eb4425 100644
--- a/src/H5S.c
+++ b/src/H5S.c
@@ -190,7 +190,7 @@ H5S_create(H5S_class_t type)
FUNC_ENTER_NOAPI(NULL)
/* Create a new dataspace */
- if(NULL == (new_ds = H5FL_MALLOC(H5S_t)))
+ if(NULL == (new_ds = H5FL_CALLOC(H5S_t)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
/* Initialize default dataspace state */
diff --git a/test/th5s.c b/test/th5s.c
index f2d2693..dcee25f 100644
--- a/test/th5s.c
+++ b/test/th5s.c
@@ -2331,6 +2331,48 @@ test_h5s_extent_copy(void)
/****************************************************************
**
+** test_h5s_bug1(): Test Creating dataspace with H5Screate then
+* setting extent with H5Sextent_copy.
+**
+****************************************************************/
+static void
+test_h5s_bug1(void)
+{
+ hid_t space1; /* Dataspace to copy extent to */
+ hid_t space2; /* Scalar dataspace */
+ hsize_t dims[2] = {10, 10}; /* Dimensions */
+ hsize_t start[2] = {0, 0}; /* Hyperslab start */
+ htri_t select_valid; /* Whether the dataspace selection is valid */
+ herr_t ret; /* Generic error return */
+
+ /* Create dataspaces */
+ space1 = H5Screate(H5S_SIMPLE);
+ CHECK(space1, FAIL, "H5Screate");
+ space2 = H5Screate_simple(2, dims, NULL);
+ CHECK(space2, FAIL, "H5Screate");
+
+ /* Copy extent to space1 */
+ ret = H5Sextent_copy(space1, space2);
+ CHECK(ret, FAIL, "H5Sextent_copy");
+
+ /* Select hyperslab in space1 containing entire extent */
+ ret = H5Sselect_hyperslab(space1, H5S_SELECT_SET, start, NULL, dims, NULL);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Check that space1's selection is valid */
+ select_valid = H5Sselect_valid(space1);
+ CHECK(select_valid, FAIL, "H5Sselect_valid");
+ VERIFY(select_valid, TRUE, "H5Sselect_valid result");
+
+ /* Close dataspaces */
+ ret = H5Sclose(space1);
+ CHECK(ret, FAIL, "H5Sclose");
+ ret = H5Sclose(space2);
+ CHECK(ret, FAIL, "H5Sclose");
+} /* test_h5s_bug1() */
+
+/****************************************************************
+**
** test_h5s(): Main H5S (dataspace) testing routine.
**
****************************************************************/
@@ -2355,6 +2397,7 @@ test_h5s(void)
test_h5s_extent_equal(); /* Test extent comparison code */
test_h5s_extent_copy(); /* Test extent copy code */
+ test_h5s_bug1(); /* Test bug in offset initialization */
} /* test_h5s() */