Skip to content

Commit 590fad6

Browse files
committed
Fix vuln OSV-2024-381
1 parent 966454a commit 590fad6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/H5Faccum.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,22 @@ H5F__accum_free(H5F_shared_t *f_sh, H5FD_mem_t H5_ATTR_UNUSED type, haddr_t addr
891891
size_t new_accum_size; /* Size of new accumulator buffer */
892892

893893
/* Calculate the size of the overlap with the accumulator, etc. */
894+
if (H5F_addr_overflow(addr, size)) {
895+
HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "address overflow when calculating overlap size");
896+
}
894897
H5_CHECKED_ASSIGN(overlap_size, size_t, (addr + size) - accum->loc, haddr_t);
895898
new_accum_size = accum->size - overlap_size;
896899

897900
/* Move the accumulator buffer information to eliminate the freed block */
901+
if (new_accum_size > accum->alloc_size) {
902+
unsigned char *new_buf = (unsigned char *)H5MM_realloc(accum->buf, new_accum_size);
903+
if (!new_buf) {
904+
/* Handle allocation failure */
905+
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for metadata accumulator buffer");
906+
}
907+
accum->buf = new_buf;
908+
accum->alloc_size = new_accum_size;
909+
}
898910
HDmemmove(accum->buf, accum->buf + overlap_size, new_accum_size);
899911

900912
/* Adjust the accumulator information */

0 commit comments

Comments
 (0)