Skip to content

Commit 6c86f97

Browse files
authored
Malformed files can have a zero name-length, which when subtracted lead to an overflow and an out-of-bounds read. Check that name length is not too small in addition to checking for an overflow directly.
1 parent 4310c19 commit 6c86f97

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

release_docs/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,11 @@ Added Fortran wrapper h5fdsubfiling_get_file_mapping_f() for the subfiling file
659659

660660
Fixed GitHub issue [#4952](https://github.com/HDFGroup/hdf5/issues/4952)
661661

662+
### Fixed security issue CVE-2025-2310
663+
664+
A malformed HDF5 file could have an attribute with a recorded name length of zero.This would lead to an overflow and an invalid memory access. An integrity check
665+
has been added to detect this case and safely stop file decoding.
666+
662667
## Java Library
663668

664669
### Renamed the Callbacks.java file to H5Callbacks.java

src/H5Oattr.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ H5O__attr_decode(H5F_t *f, H5O_t *open_oh, unsigned H5_ATTR_UNUSED mesg_flags, u
167167
if (H5_IS_BUFFER_OVERFLOW(p, 2, p_end))
168168
HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
169169
UINT16DECODE(p, name_len); /* Including null */
170+
171+
/* Verify that retrieved name length (including null byte) is valid */
172+
if (name_len <= 1)
173+
HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, NULL, "decoded name length is invalid");
174+
170175
if (H5_IS_BUFFER_OVERFLOW(p, 2, p_end))
171176
HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
172177
UINT16DECODE(p, attr->shared->dt_size);
@@ -190,6 +195,7 @@ H5O__attr_decode(H5F_t *f, H5O_t *open_oh, unsigned H5_ATTR_UNUSED mesg_flags, u
190195
*/
191196
if (H5_IS_BUFFER_OVERFLOW(p, name_len, p_end))
192197
HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
198+
193199
if (NULL == (attr->shared->name = H5MM_strndup((const char *)p, name_len - 1)))
194200
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
195201

0 commit comments

Comments
 (0)