Fix CVE-2025-2310 (#5872)

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.
This commit is contained in:
Matt L
2025-10-09 16:10:23 -05:00
committed by GitHub
parent 4310c19608
commit 6c86f97e03
2 changed files with 11 additions and 0 deletions
+5
View File
@@ -659,6 +659,11 @@ Added Fortran wrapper h5fdsubfiling_get_file_mapping_f() for the subfiling file
Fixed GitHub issue [#4952](https://github.com/HDFGroup/hdf5/issues/4952)
### Fixed security issue CVE-2025-2310
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
has been added to detect this case and safely stop file decoding.
## Java Library
### Renamed the Callbacks.java file to H5Callbacks.java
+6
View File
@@ -167,6 +167,11 @@ H5O__attr_decode(H5F_t *f, H5O_t *open_oh, unsigned H5_ATTR_UNUSED mesg_flags, u
if (H5_IS_BUFFER_OVERFLOW(p, 2, p_end))
HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
UINT16DECODE(p, name_len); /* Including null */
/* Verify that retrieved name length (including null byte) is valid */
if (name_len <= 1)
HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, NULL, "decoded name length is invalid");
if (H5_IS_BUFFER_OVERFLOW(p, 2, p_end))
HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
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
*/
if (H5_IS_BUFFER_OVERFLOW(p, name_len, p_end))
HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
if (NULL == (attr->shared->name = H5MM_strndup((const char *)p, name_len - 1)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");