Skip to content

Fix FPE when opening a chunked dataset with a zero-sized chunk dimension - #6760

Open
tbeu wants to merge 1 commit into
HDFGroup:developfrom
tbeu:fix-zero-chunk-dim-fpe
Open

tbeu wants to merge 1 commit into
HDFGroup:developfrom
tbeu:fix-zero-chunk-dim-fpe

Conversation

@tbeu

@tbeu tbeu commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Problem

H5D__chunk_set_info_real() computed the number of chunks in each dimension by dividing by the chunk dimension before validating that the dimension was non-zero. The existing validation was additionally only reached in the else branch, i.e. when the maximum dimension was not H5S_UNLIMITED. A corrupt file that encoded a zero-sized chunk dimension therefore triggered an integer division by zero (a floating point exception) while the dataset was being opened.

One-dimensional datasets were reachable because H5D__chunk_init() validates the chunk dimensions only inside its if (dset->shared->ndims > 1) block, so a 1-D chunked dataset with a zero chunk dimension reached H5D__chunk_set_info() -> H5D__chunk_set_info_real() unguarded. This matches the crash stack reported below (H5D__chunk_init -> H5D__chunk_set_info -> H5D__chunk_set_info_real).

Solution

The chunk dimension is now validated before the divisions, covering every dimension and both the limited and unlimited cases. Such a dataset is rejected with a normal HDF5 error instead of crashing.

Reproducer

Opening dataset i16 from clusterfuzz-testcase-minimized-matio_hyperslab_fuzzer-4546410763321344 (found via matio) crashes with STATUS_INTEGER_DIVIDE_BY_ZERO (0xC0000094) on Windows and an ASan FPE on Linux. After the fix, H5Dopen returns an error and the library no longer crashes.

Links

@github-actions

Copy link
Copy Markdown
Contributor

Review Checklist

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

H5D__chunk_set_info_real() divided by the chunk dimension before validating
that it was non-zero, and the existing check was only reached when the maximum
dimension was not H5S_UNLIMITED. A corrupt file encoding a zero-sized chunk
dimension therefore crashed the library with an integer division by zero (FPE)
while the dataset was being opened. One-dimensional datasets were reachable
because H5D__chunk_init() validates the chunk dimensions only for datasets with
more than one dimension.

Validate the chunk dimension before the divisions, covering both the limited
and unlimited cases. Such a dataset is now rejected with a normal error.

Reported by OSS-Fuzz via matio.
@tbeu
tbeu force-pushed the fix-zero-chunk-dim-fpe branch from 46acf16 to 8dbf869 Compare October 20, 2026 21:13

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To be triaged

Development

Successfully merging this pull request may close these issues.

1 participant