Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault in H5Scombine_select #5296

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/H5Shyper.c
Original file line number Diff line number Diff line change
Expand Up @@ -10699,7 +10699,8 @@ H5S__combine_select(H5S_t *space1, H5S_seloper_t op, H5S_t *space2)
} /* end else */

/* Set unlim_dim */
new_space->select.sel_info.hslab->unlim_dim = -1;
if (H5S_SEL_HYPERSLABS == H5S_GET_SELECT_TYPE(new_space))
new_space->select.sel_info.hslab->unlim_dim = -1;

/* Set return value */
ret_value = new_space;
Expand Down
52 changes: 52 additions & 0 deletions test/th5s.c
Original file line number Diff line number Diff line change
Expand Up @@ -3342,6 +3342,57 @@ test_h5s_bug2(void)
CHECK(ret, FAIL, "H5Sclose");
} /* test_h5s_bug2() */

/****************************************************************
**
** test_h5s_bug3(): Test combining hyperslabs in a way that used
** to trip up H5S__combine_select()
**
****************************************************************/
static void
test_h5s_bug3(void)
{
hsize_t dims[1] = {10};
hsize_t start[1] = {0};
hsize_t count[1] = {1};
herr_t ret = SUCCEED;
hid_t space1 = H5I_INVALID_HID;
hid_t space2 = H5I_INVALID_HID;
hid_t space3 = H5I_INVALID_HID;

space1 = H5Screate_simple(1, dims, NULL);
CHECK(space1, FAIL, "H5Screate_simple");

space2 = H5Screate_simple(1, dims, NULL);
CHECK(space2, FAIL, "H5Screate_simple");

/* Select a single, different element in each dataspace */
start[0] = 0;
count[0] = 1;
ret = H5Sselect_hyperslab(space1, H5S_SELECT_SET, start, NULL, count, NULL);
CHECK(ret, FAIL, "H5Sselect_hyperslab");

start[0] = 1;
count[0] = 1;
ret = H5Sselect_hyperslab(space2, H5S_SELECT_SET, start, NULL, count, NULL);
CHECK(ret, FAIL, "H5Sselect_hyperslab");

/* Combine the selections with AND, resulting in a "none" selection.
* H5Scombine_select previously used to attempt to set information
* in a hyperslab-specific field, even when the resulting selection
* wasn't a hyperslab.
*/
space3 = H5Scombine_select(space1, H5S_SELECT_AND, space2);
CHECK(space3, FAIL, "H5Scombine_select");

/* Close dataspaces */
ret = H5Sclose(space1);
CHECK(ret, FAIL, "H5Sclose");
ret = H5Sclose(space2);
CHECK(ret, FAIL, "H5Sclose");
ret = H5Sclose(space3);
CHECK(ret, FAIL, "H5Sclose");
} /* test_h5s_bug3() */

/*-------------------------------------------------------------------------
* Function: test_versionbounds
*
Expand Down Expand Up @@ -3525,6 +3576,7 @@ test_h5s(void H5_ATTR_UNUSED *params)
test_h5s_extent_copy(); /* Test extent copy code */
test_h5s_bug1(); /* Test bug in offset initialization */
test_h5s_bug2(); /* Test bug found in H5S__hyper_update_diminfo() */
test_h5s_bug3(); /* Test bug found in H5S__combine_select() */
test_versionbounds(); /* Test version bounds with dataspace */
} /* test_h5s() */

Expand Down
Loading