diff --git a/release_docs/CHANGELOG.md b/release_docs/CHANGELOG.md index 1a9617a1115..0a25a433231 100644 --- a/release_docs/CHANGELOG.md +++ b/release_docs/CHANGELOG.md @@ -495,6 +495,11 @@ Simple example programs showing how to use complex number datatypes have been ad ## Library +### Fixed security issue CVE-2025-2925 + Actual_len + H5C_IMAGE_EXTRA_SPACE, which was used by H5MM_realloc as the size input, could equal 0 due to bad inputs. When H5MM_realloc was called, it freed image, but then could get sent to done before new_image could be assigned to image. Because the pointer for image wasn't null, it was freed again in done, causing a double-free vulnerability. H5C__load_entry() now checks for an image buffer length of 0 before calling H5MM_realloc. + + Fixes Github issue #5383 + ### Fixed security issue CVE-2025-6857 An HDF5 file had a corrupted v1 B-tree that would result in a stack overflow when performing a lookup on it. This has been fixed with additional integrity checks. diff --git a/src/H5Centry.c b/src/H5Centry.c index 33728f33398..851ea730a50 100644 --- a/src/H5Centry.c +++ b/src/H5Centry.c @@ -1052,9 +1052,14 @@ H5C__load_entry(H5F_t *f, */ do { if (actual_len != len) { + /* Verify that the length isn't a bad value */ + if (len == 0) + HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, NULL, "len is a bad value"); + if (NULL == (new_image = H5MM_realloc(image, len + H5C_IMAGE_EXTRA_SPACE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, NULL, "image null after H5MM_realloc()"); image = (uint8_t *)new_image; + #if H5C_DO_MEMORY_SANITY_CHECKS H5MM_memcpy(image + len, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); #endif /* H5C_DO_MEMORY_SANITY_CHECKS */ @@ -1105,10 +1110,15 @@ H5C__load_entry(H5F_t *f, if (H5C__verify_len_eoa(f, type, addr, &actual_len, true) < 0) HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, NULL, "actual_len exceeds EOA"); + /* Verify that the length isn't 0 */ + if (actual_len == 0) + HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, NULL, "actual_len is a bad value"); + /* Expand buffer to new size */ if (NULL == (new_image = H5MM_realloc(image, actual_len + H5C_IMAGE_EXTRA_SPACE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, NULL, "image null after H5MM_realloc()"); image = (uint8_t *)new_image; + #if H5C_DO_MEMORY_SANITY_CHECKS H5MM_memcpy(image + actual_len, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); #endif /* H5C_DO_MEMORY_SANITY_CHECKS */