Skip to content

Commit 1508f3f

Browse files
author
Glenn Song
committed
Address Neil's comments and move check to when the value is read
1 parent 1a9431b commit 1508f3f

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

release_docs/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ Simple example programs showing how to use complex number datatypes have been ad
496496
## Library
497497

498498
### Fixed security issue CVE-2025-2915
499-
In H5F__accum_free, a heap-based buffer overflow issue was occurring due to calculating a new_accum_size that did not make sense due to an integer overflow. A new check has been added to make sure that accum->size - overlap_size can't result in a negative number, which prevents strange behavior later.
499+
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.
500500

501501
Fixes GitHub issue #5380
502502

src/H5Faccum.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +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-
if (overlap_size > accum->size)
883-
HGOTO_ERROR(H5E_IO, H5E_BADVALUE, FAIL, "new accumulator size negative");
882+
/* Sanity check */
883+
/* Overlap size should not result in "negative" value after subtraction */
884+
assert(overlap_size > accum->size);
884885
new_accum_size = accum->size - overlap_size;
885886

886887
/* 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_DEFAULT))
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)