Skip to content

Commit

Permalink
Fix potential buffer read overflows in H5PB_read
Browse files Browse the repository at this point in the history
H5PB_read previously did not account for the fact that the size of the
read it's performing could overflow the page buffer pointer, depending
on the calculated offset for the read. This has been fixed by adjusting
the size of the read if it's determined that it would overflow the page.
  • Loading branch information
jhendersonHDF committed Mar 29, 2024
1 parent 16ba713 commit 0e7378c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions release_docs/RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,13 @@ Bug Fixes since HDF5-1.14.0 release

Library
-------
- Fixed potential buffer read overflows in H5PB_read

H5PB_read previously did not account for the fact that the size of the
read it's performing could overflow the page buffer pointer, depending
on the calculated offset for the read. This has been fixed by adjusting
the size of the read if it's determined that it would overflow the page.

- Fixed CVE-2017-17507

This CVE was previously declared fixed, but later testing with a static
Expand Down
11 changes: 10 additions & 1 deletion src/H5PB.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ H5PB_read(H5F_shared_t *f_sh, H5FD_mem_t type, haddr_t addr, size_t size, void *
if (H5FD_MEM_DRAW == type) {
last_page_addr = ((addr + size - 1) / page_buf->page_size) * page_buf->page_size;

/* How many pages does this write span */
/* How many pages does this read span */
num_touched_pages =
(last_page_addr / page_buf->page_size + 1) - (first_page_addr / page_buf->page_size);
if (first_page_addr == last_page_addr) {
Expand Down Expand Up @@ -835,6 +835,10 @@ H5PB_read(H5F_shared_t *f_sh, H5FD_mem_t type, haddr_t addr, size_t size, void *
offset = (0 == i ? addr - page_entry->addr : 0);
buf_offset = (0 == i ? 0 : size - access_size);

/* Account for reads that would overflow a page */
if (offset + access_size > page_buf->page_size)
access_size = page_buf->page_size - offset;

/* copy the requested data from the page into the input buffer */
H5MM_memcpy((uint8_t *)buf + buf_offset, (uint8_t *)page_entry->page_buf_ptr + offset,
access_size);
Expand Down Expand Up @@ -905,6 +909,11 @@ H5PB_read(H5F_shared_t *f_sh, H5FD_mem_t type, haddr_t addr, size_t size, void *
/* Copy the requested data from the page into the input buffer */
offset = (0 == i ? addr - search_addr : 0);
buf_offset = (0 == i ? 0 : size - access_size);

/* Account for reads that would overflow a page */
if (offset + access_size > page_buf->page_size)
access_size = page_buf->page_size - offset;

H5MM_memcpy((uint8_t *)buf + buf_offset, (uint8_t *)new_page_buf + offset, access_size);

/* Create the new PB entry */
Expand Down

0 comments on commit 0e7378c

Please sign in to comment.