Skip to content

Reject chunked datasets with mismatched chunk/dspace rank at open time#6508

Draft
mattjala wants to merge 3 commits into
HDFGroup:developfrom
mattjala:h5repack_hyperslab_sigfpe
Draft

Reject chunked datasets with mismatched chunk/dspace rank at open time#6508
mattjala wants to merge 3 commits into
HDFGroup:developfrom
mattjala:h5repack_hyperslab_sigfpe

Conversation

@mattjala

@mattjala mattjala commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

H5D__chunk_construct() only validates that the chunk layout dimensionality matches the dataspace rank at dataset creation time. When an existing dataset is opened, H5D__chunk_init() didn't repeat the check, so a file whose stored chunk rank disagreed with its dataspace rank was accepted.

During chunk I/O the memory-selection rank (from the dataspace) and the file-selection rank (chunk ndims - 1) then differ, which produces a zero stride that causes a divide-by-zero in H5S__hyper_iter_get_seq_list().

H5D__chunk_init() now performs the same dimensionality check on open (the stored chunk rank includes the extra element-size dimension, so it must be exactly one greater than the dataspace rank) and rejects a mismatch with an error.

Added test_chunk_dims_mismatch() as a regression test for this fix within test/dsets.c

Fixes #6491

H5D__chunk_construct() validates that the chunk layout dimensionality
matches the dataspace rank, but that runs only at dataset creation time.
When an existing dataset is opened, H5D__chunk_init() didn't repeat the
check, so a file whose stored chunk rank disagreed with its dataspace rank
was accepted. During chunk I/O the memory-selection rank (from the
dataspace) and the file-selection rank (chunk ndims - 1) then differ, which
produces a zero stride that causes a divide-by-zero in
H5S__hyper_iter_get_seq_list().

H5D__chunk_init() now performs the same dimensionality check on open (the
stored chunk rank includes the extra element-size dimension, so it must be
exactly one greater than the dataspace rank) and rejects a mismatch with an
error.

Added test_chunk_dims_mismatch() as a regression test in test/dsets.c

Fixes HDFGroup#6491
Copilot AI review requested due to automatic review settings July 6, 2026 20:39
@mattjala mattjala requested a review from lrknox as a code owner July 6, 2026 20:39
@mattjala mattjala added the Component - C Library Core C library issues (usually in the src directory) label Jul 6, 2026
@mattjala mattjala added the Component - Testing Code in test or testpar directories, GitHub workflows label Jul 6, 2026
@mattjala mattjala added the Type - Security Security issues, including library crashers and memory leaks label Jul 6, 2026
@github-project-automation github-project-automation Bot moved this to To be triaged in HDF5 - TRIAGE & TRACK Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Checklist

This PR touches the following areas. Each needs a sign-off
from its listed owners before merging.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request hardens chunked-dataset open-time validation to reject malformed files where the stored chunk layout dimensionality disagrees with the dataset dataspace rank, preventing a downstream divide-by-zero during chunk I/O selection iteration (Fixes #6491).

Changes:

  • Add an open-time check in H5D__chunk_init() to ensure stored chunk dimensionality matches dataspace_rank + 1 (datatype-size dimension).
  • Add a regression test (test_chunk_dims_mismatch()) that verifies opening such a malformed chunked dataset fails cleanly.
  • Add a generator and CMake wiring for the malformed reference file, plus a changelog entry documenting the fix.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/H5Dchunk.c Adds open-time validation to reject datasets with mismatched stored chunk ndims vs dataspace rank.
test/dsets.c Adds a regression test that asserts malformed chunk-layout dimensionality is rejected on open.
test/gen_bad_chunk.c Adds a generator program for producing a malformed chunked dataset file used by the regression test.
test/CMakeTests.cmake Registers the new malformed reference file and generator executable in the CMake test configuration.
release_docs/CHANGELOG.md Documents the crash fix and the new open-time validation behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/gen_bad_chunk.c Outdated
Comment thread test/gen_bad_chunk.c Outdated
Comment thread test/dsets.c Outdated
mattjala and others added 2 commits July 6, 2026 16:23
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@mattjala mattjala force-pushed the h5repack_hyperslab_sigfpe branch from 0ccb2cb to daedfba Compare July 6, 2026 21:52
@github-actions github-actions Bot requested review from glennsong09 and lrknox and removed request for glennsong09 and lrknox July 6, 2026 21:52
Comment thread src/H5Dchunk.c
* dimensionality is consistent with the dataspace rank. H5D__chunk_construct()
* performs this check at creation time, but it must also be performed
* here to catch malformed files. */
if (open_op && dset->shared->layout.u.chunk.ndims != dset->shared->ndims + 1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this check specific to this place in the dataset code? It seems like something that would be worth validating at the layout message decode time instead.

Comment thread release_docs/CHANGELOG.md

### Fixed a crash when reading a chunked dataset whose chunk rank mismatches the dataspace

The chunk layout's stored dimensionality was validated against the dataspace rank at creation time, but not at open time, so a file whose stored chunk rank disagrees with its dataspace rank would not be caught. The resulting inconsistent selection ranks during chunk I/O caused a divide-by-zero in the hyperslab iterator. The chunk dimensionality is now also validated on open, and such a dataset is rejected with an error instead of crashing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

disagrees -> disagreed
would not be caught -> was not caught

@github-project-automation github-project-automation Bot moved this from To be triaged to In progress in HDF5 - TRIAGE & TRACK Jul 7, 2026
@mattjala mattjala marked this pull request as draft July 7, 2026 19:59
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) Component - Testing Code in test or testpar directories, GitHub workflows Type - Security Security issues, including library crashers and memory leaks

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

h5repack: SIGFPE in H5S__hyper_iter_get_seq_list when repacking dataset

4 participants