Repository navigation
Conversation
A dataset's datatype is shared by all open handles of the dataset, and H5T_set_loc() stamps the file of the handle that opened it first into every variable-length type it can reach, also below compound members and array base types. H5T_patch_vlen_file() repairs that file before reading or writing data, but only for a variable-length type at the top level. After the file of the first handle was closed, reading through another handle therefore crashed in H5F_addr_decode() for a variable-length string in a compound type (h5py/h5py#2920). Walk the same subtypes as H5T_set_loc() instead. Based on the analysis and patch in https://github.com/beitler/hdf5-vlen. Co-authored-by: anton <2046752+beitler@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
H5D_get_create_plist() and the storage initialization of H5D__alloc_storage() and H5D__set_extent() convert the fill value with the dataset's shared datatype, without repairing the file of its variable-length types first as H5Dread() and H5Dwrite() do. After the file of the handle that opened the dataset first was closed, this crashed in H5F_addr_decode() for a dataset with a variable-length fill value. netCDF-C calls H5Dget_create_plist() when opening a file, so it crashed when opening a netCDF-4 file with string variables again after closing one of several handles to it. Add a test that uses variable-length data through a dataset handle after closing another handle of the same dataset, for these cases and for the variable-length type in a compound type from the previous commit. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
headtr1ck
requested review from
fortnern,
glennsong09,
hyoklee,
jhendersonHDF,
lrknox,
mattjala and
vchoi-hdfgroup
as code owners
October 8, 2026 11:35
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions
Bot
removed request for
fortnern,
glennsong09,
jhendersonHDF,
lrknox and
mattjala
October 8, 2026 11:36
Contributor
Review ChecklistThis PR touches the following areas. Each needs a sign-off
|
hyoklee
approved these changes
Oct 8, 2026
hyoklee
reviewed
Oct 8, 2026
|
|
||
| ### Fixed crashes when using variable-length data after closing another handle of the same dataset | ||
|
|
||
| A dataset's datatype is shared by all open handles of the dataset, and its variable-length types refer to the file of the handle that opened the dataset first. After that file handle was closed, other handles of the same dataset, e.g. from opening the same file twice, still converted variable-length data with the closed file, which crashed in `H5F_addr_decode()`. `H5T_patch_vlen_file()` repaired the file only for a variable-length type at the top level of the datatype, and only when reading or writing data, but not for variable-length types nested in compound or array types, or when converting a variable-length fill value in `H5Dget_create_plist()` or while initializing storage, e.g. in `H5Dset_extent()`. Opening a netCDF-4 file with string variables calls `H5Dget_create_plist()`, so this crashed netCDF-C and netCDF4-python when a file was opened again after closing one of several handles to it. `H5T_patch_vlen_file()` now repairs nested variable-length types as well, and is also called before converting fill values. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
A dataset's datatype is shared by all open handles of the dataset, and its variable-length types store the file of the handle that opened the dataset first. After that file handle is closed, e.g. when the same file was opened twice, converting variable-length data through another handle of the dataset crashes in
H5F_addr_decode().H5T_patch_vlen_file()repairs this, but only for a top-level variable-length type and only before reading or writing data.H5T_patch_vlen_file()also repairs variable-length types nested in compound and array types, walking the same subtypes asH5T_set_loc(). This fixes reading a vlen string in a compound type (Segfault on interleaved reads on same dataset from different file handles h5py/h5py#2920); the patch is from the analysis in https://github.com/beitler/hdf5-vlen.H5D_get_create_plist(),H5D__alloc_storage()andH5D__set_extent()callH5T_patch_vlen_file()before converting the fill value. Without it,H5Dget_create_plist()on a vlen string dataset with a fill value crashed, which netCDF-C calls when opening a netCDF-4 file with string variables (Close files of garbage collected file managers once their lock is free pydata/xarray#11692), as didH5Dset_extent(), which writes the fill value into new storage.test_vl_closed_handleintest/tvlstr.cfor all three cases; it segfaults without the changes insrc/.Issue ticket number (GitHub or JIRA)
Fixes #6721 (see also h5py/h5py#2920 and pydata/xarray#11692)
Checklist before requesting a review
[This is Claude Code on behalf of Michael Niklas]
🤖 Generated with Claude Code