From 6c86f97e03c6dc7d7bd2bae9acc422bdc3438ff4 Mon Sep 17 00:00:00 2001 From: Matt L <124107509+mattjala@users.noreply.github.com> Date: Thu, 9 Oct 2025 16:10:23 -0500 Subject: [PATCH] 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. --- release_docs/CHANGELOG.md | 5 +++++ src/H5Oattr.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/release_docs/CHANGELOG.md b/release_docs/CHANGELOG.md index eaaa156174c..557b6404590 100644 --- a/release_docs/CHANGELOG.md +++ b/release_docs/CHANGELOG.md @@ -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 diff --git a/src/H5Oattr.c b/src/H5Oattr.c index 1f11892e2f1..4618b69b9ac 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -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");