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 a memory corruption issue in H5S__point_project_simple #2626

Merged
merged 1 commit into from
Mar 24, 2023

Conversation

jhendersonHDF
Copy link
Collaborator

No description provided.

@jhendersonHDF jhendersonHDF added Merge - To 1.12 Merge - To 1.14 This needs to be merged to HDF5 1.14 Priority - 0. Blocker ⛔ This MUST be merged for the release to happen Component - C Library Core C library issues (usually in the src directory) Type - Bug Please report security issues to help@hdfgroup.org instead of creating an issue on GitHub labels Mar 23, 2023
@@ -2319,7 +2319,7 @@ H5S__point_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *of
/* Copy over the point's coordinates */
HDmemset(new_node->pnt, 0, sizeof(hsize_t) * rank_diff);
H5MM_memcpy(&new_node->pnt[rank_diff], base_node->pnt,
(new_space->extent.rank * sizeof(hsize_t)));
(base_space->extent.rank * sizeof(hsize_t)));
Copy link
Collaborator Author

@jhendersonHDF jhendersonHDF Mar 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you expand the code above, you can see that this block assumes new_space->extent.rank > base_space->extent.rank. This copying code allocates a new_space->extent.rank-sized array of hsize_t for the point coordinates, then offsets into the pnt array by rank_diff which is calculated by new_space->extent.rank - base_space->extent.rank. However, it previously tried copying a new_space->extent.rank amount of points into the array AFTER offsetting into the array, whereas there would only be room left for a base_space->extent.rank amount of points. This issue cropped up with a Developer build that disables free lists, so this issue has likely been around for a long time but went unnoticed because the free lists were allocating enough room that we could happily write over.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@@ -2319,7 +2319,7 @@ H5S__point_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *of
/* Copy over the point's coordinates */
HDmemset(new_node->pnt, 0, sizeof(hsize_t) * rank_diff);
H5MM_memcpy(&new_node->pnt[rank_diff], base_node->pnt,
(new_space->extent.rank * sizeof(hsize_t)));
(base_space->extent.rank * sizeof(hsize_t)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@lrknox lrknox merged commit 31c26e7 into HDFGroup:develop Mar 24, 2023
jhendersonHDF added a commit to jhendersonHDF/hdf5 that referenced this pull request Mar 24, 2023
jhendersonHDF added a commit to jhendersonHDF/hdf5 that referenced this pull request Mar 24, 2023
@jhendersonHDF jhendersonHDF deleted the H5S_point_project_fix branch March 24, 2023 22:47
brtnfld pushed a commit to brtnfld/hdf5 that referenced this pull request May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - C Library Core C library issues (usually in the src directory) Merge - To 1.14 This needs to be merged to HDF5 1.14 Priority - 0. Blocker ⛔ This MUST be merged for the release to happen Type - Bug Please report security issues to help@hdfgroup.org instead of creating an issue on GitHub
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants