You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix memory safety vulnerabilities in high-level and VFD code
H5FDstdio (src/H5FDstdio.c):
- Fix five error paths in H5FD_stdio_open() that called fclose(f) after
free(file): the correct resource to close is file->fp. Reorder to
fclose before free to match standard cleanup idiom and prevent file
descriptor leaks under memory-pressure failures.
H5VLnative (src/H5VLnative.c):
- Add assert(obj) and assert(file) to H5VL_native_get_file_struct() to
catch NULL-pointer programming errors early in debug builds.
H5LT (hl/src/H5LT.c):
- Add NULL check after strdup() in H5LTtext_to_dtype(); push H5E_NOSPACE
so the HDF5 error stack is populated on OOM.
- Fix H5Tclose(super) leak in H5T_ENUM, H5T_VLEN, H5T_ARRAY, H5T_COMPLEX
branches of H5LT_dtype_to_text(): super was only closed on the success
path; any failure between H5Tget_super and the final realloc_and_append
leaked the type ID. Super is now closed immediately after use.
- Refactor the repeated "get super-type text and append" pattern (four
near-identical ~15-line blocks) into static helper append_dtype_super_text().
Pushes H5E_NOSPACE on internal calloc failure.
- Rewrite realloc_and_append() doc comment to document the asymmetric
ownership contract (callee frees buf on realloc failure in
library-managed mode; no free in user-buf mode).
- Move the buf == NULL guard to before the _no_user_buf branch so both
modes short-circuit identically.
H5TB (hl/src/H5TB.c):
- Clarify H5TBget_field_info() else-branch comment: the two-branch copy
structure is an efficiency optimization (copy name_len+1 bytes rather
than HLTB_MAX_FIELD_LEN-1), not a backward-compatibility concern.
CHANGELOG (release_docs/CHANGELOG.md):
- Add entries for the stdio VFD leak fix, VOL NULL checks, and H5LT
memory-safety improvements.
Copy file name to clipboardExpand all lines: release_docs/CHANGELOG.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -140,6 +140,14 @@ We would like to thank the many HDF5 community members who contributed to this r
140
140
141
141
## Library
142
142
143
+
### Fixed file descriptor leaks in stdio VFD error paths
144
+
145
+
Fixed multiple resource leaks in the H5FDstdio driver where file descriptors were not properly closed on error paths. The error handling code was incorrectly attempting to close a local variable instead of the file pointer stored in the file structure, leading to file descriptor leaks. This issue affected 5 error paths in `H5FD_stdio_open()` and could cause file descriptor exhaustion in long-running applications.
146
+
147
+
### Added defensive NULL pointer checks in native VOL connector
148
+
149
+
Added assertion checks for NULL pointer parameters in `H5VL_native_get_file_struct()` to catch programming errors earlier and improve code robustness.
150
+
143
151
### Added checks for data filter behavior
144
152
145
153
The library now verifies that the returned data size from a data filter's filter callback function can fit inside the returned data buffer size. The library also checks that, when data is filtered then unfiltered (filtered in reverse), the returned data size is exactly the same as the original data size.
@@ -194,6 +202,16 @@ We would like to thank the many HDF5 community members who contributed to this r
194
202
header `H5TBpublic.h`. Applications can now use this constant to correctly size their
195
203
`field_names[]` buffers when calling `H5TBget_field_info()`.
196
204
205
+
### Fixed memory leaks and improved safety in H5LT functions
206
+
207
+
- Fixed memory leak in `H5LTtext_to_dtype()` by adding NULL check after `strdup()` call
208
+
- Added defensive NULL checks and pointer nullification after `free()` calls to prevent use-after-free bugs
209
+
- Improved documentation for `realloc_and_append()` internal function with detailed parameter contracts and preconditions
210
+
211
+
### Eliminated code duplication in H5LT datatype conversion
212
+
213
+
Refactored `H5LT_dtype_to_text()` by extracting common super-type handling logic into a new helper function `H5LT_append_dtype_super_text()`. This eliminates approximately 80 lines of duplicated code that was previously repeated across 4 datatype cases (ENUM, VLEN, ARRAY, COMPLEX), improving maintainability and reducing the risk of inconsistent behavior.
214
+
197
215
### Fixed H5TBread_fields_name/H5TBwrite_fields_name matching the wrong field when one field name is a prefix of another
198
216
199
217
H5TB_find_field() used strncmp() limited to strlen(field) when comparing the last entry of the supplied comma-separated field list against a table member name. This matched any user-supplied name whose leading characters equaled an existing field name (for example, requesting "PressureExtra" on a table containing "Pressure" would silently operate on the "Pressure" field). The comparison has been changed to strcmp() so full names must match exactly. In addition, H5TBwrite_fields_name() now returns an error when none of the requested field names are found (previously it silently performed a no-op write), matching the existing behavior of H5TBread_fields_name().
0 commit comments