Skip to content

Commit 26a76ba

Browse files
authored
This PR fixes issue #5380, which has a heap based buffer overflow after H5MF_xfree is called on an address of 0 (file superblock). This PR changes an assert making sure addr isn't 0 to an if check. The bug was first reproduced using the fuzzer and the POC file from #5380. With this change, the heap based buffer overflow no longer occurs.
1 parent 7dd1102 commit 26a76ba

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

release_docs/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,12 @@ Added Fortran wrapper h5fdsubfiling_get_file_mapping_f() for the subfiling file
557557

558558
## Library
559559

560+
### Fixed security issue CVE-2025-2915 and OSV-2024-381
561+
562+
Fixed a heap-based buffer overflow in H5F__accum_free caused by an integer overflow when calculating new_accum_size. Added validation in H5O__mdci_decode to detect and reject invalid values early, preventing the overflow condition.
563+
564+
Fixes GitHub issue #5380
565+
560566
### Fixed security issue CVE-2025-7068
561567

562568
Failures during the discard process on a metadata cache entry could cause the library to skip calling the callback to free the cache entry. This could result in resource leaks and issues with flushing and closing the metadata cache during file close. This has been fixed by noting errors during the discard process, but attempting to fully free a cache entry before signalling that an error has occurred.

src/H5Faccum.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,9 @@ H5F__accum_free(H5F_shared_t *f_sh, H5FD_mem_t H5_ATTR_UNUSED type, haddr_t addr
879879

880880
/* Calculate the size of the overlap with the accumulator, etc. */
881881
H5_CHECKED_ASSIGN(overlap_size, size_t, (addr + size) - accum->loc, haddr_t);
882+
/* Sanity check */
883+
/* Overlap size should not result in "negative" value after subtraction */
884+
assert(overlap_size < accum->size);
882885
new_accum_size = accum->size - overlap_size;
883886

884887
/* Move the accumulator buffer information to eliminate the freed block */

src/H5Ocache_image.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ H5O__mdci_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, unsigned H5_ATTR_UNUSE
116116
HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
117117
H5F_DECODE_LENGTH(f, p, mesg->size);
118118

119+
if (mesg->addr >= (HADDR_UNDEF - mesg->size))
120+
HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "address plus size overflows");
121+
if (mesg->addr == HADDR_UNDEF)
122+
HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "address is undefined");
123+
if ((mesg->addr + mesg->size) > H5F_get_eoa(f, H5FD_MEM_SUPER))
124+
HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "address plus size exceeds file eoa");
125+
119126
/* Set return value */
120127
ret_value = (void *)mesg;
121128

0 commit comments

Comments
 (0)