Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/H5Cimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,8 @@ H5C__decode_cache_image_header(const H5F_t *f, H5C_t *cache_ptr, const uint8_t *
size_t actual_header_len;
size_t expected_header_len;
const uint8_t *p;
herr_t ret_value = SUCCEED; /* Return value */
const uint8_t *p_end = *buf + buf_size - 1; /* End of the p buffer */
herr_t ret_value = SUCCEED; /* Return value */

FUNC_ENTER_PACKAGE

Expand All @@ -1290,7 +1291,7 @@ H5C__decode_cache_image_header(const H5F_t *f, H5C_t *cache_ptr, const uint8_t *
p = *buf;

/* Ensure buffer has enough data for signature comparison */
if (H5_IS_BUFFER_OVERFLOW(p, H5C__MDCI_BLOCK_SIGNATURE_LEN, *buf + buf_size - 1))
if (H5_IS_BUFFER_OVERFLOW(p, H5C__MDCI_BLOCK_SIGNATURE_LEN, p_end))
HGOTO_ERROR(H5E_CACHE, H5E_OVERFLOW, FAIL, "Insufficient buffer size for signature");

/* Check signature */
Expand All @@ -1299,25 +1300,33 @@ H5C__decode_cache_image_header(const H5F_t *f, H5C_t *cache_ptr, const uint8_t *
p += H5C__MDCI_BLOCK_SIGNATURE_LEN;

/* Check version */
if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buffer overflow check above if (H5_IS_BUFFER_OVERFLOW(p, H5C__MDCI_BLOCK_SIGNATURE_LEN, *buf + buf_size - 1)) should probably be updated to make use of p_end instead for consistency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhendersonHDF I made the change. Thanks!

HGOTO_ERROR(H5E_CACHE, H5E_OVERFLOW, FAIL, "ran off end of input buffer while decoding");
version = *p++;
if (version != (uint8_t)H5C__MDCI_BLOCK_VERSION_0)
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "Bad metadata cache image version");

/* Decode flags */
if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end))
HGOTO_ERROR(H5E_CACHE, H5E_OVERFLOW, FAIL, "ran off end of input buffer while decoding");
flags = *p++;
if (flags & H5C__MDCI_HEADER_HAVE_RESIZE_STATUS)
have_resize_status = true;
if (have_resize_status)
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "MDC resize status not yet supported");

/* Read image data length */
if (H5_IS_BUFFER_OVERFLOW(p, H5F_sizeof_size(f), p_end))
HGOTO_ERROR(H5E_CACHE, H5E_OVERFLOW, FAIL, "ran off end of input buffer while decoding");
H5F_DECODE_LENGTH(f, p, cache_ptr->image_data_len);

/* For now -- will become <= eventually */
if (cache_ptr->image_data_len != cache_ptr->image_len)
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "Bad metadata cache image data length");

/* Read num entries */
if (H5_IS_BUFFER_OVERFLOW(p, 4, p_end))
HGOTO_ERROR(H5E_CACHE, H5E_OVERFLOW, FAIL, "ran off end of input buffer while decoding");
UINT32DECODE(p, cache_ptr->num_entries_in_image);
if (cache_ptr->num_entries_in_image == 0)
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "Bad metadata cache entry count");
Expand Down Expand Up @@ -2392,18 +2401,18 @@ H5C__reconstruct_cache_contents(H5F_t *f, H5C_t *cache_ptr)
assert(cache_ptr->image_len > 0);

/* Decode metadata cache image header */
p = (uint8_t *)cache_ptr->image_buffer;
image_len = cache_ptr->image_len;
if (H5C__decode_cache_image_header(f, cache_ptr, &p, image_len + 1) < 0)
p = (uint8_t *)cache_ptr->image_buffer;
if (H5C__decode_cache_image_header(f, cache_ptr, &p, cache_ptr->image_len + 1) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTDECODE, FAIL, "cache image header decode failed");
assert((size_t)(p - (uint8_t *)cache_ptr->image_buffer) < image_len);
assert((size_t)(p - (uint8_t *)cache_ptr->image_buffer) < cache_ptr->image_len);

/* The image_data_len and # of entries should be defined now */
assert(cache_ptr->image_data_len > 0);
assert(cache_ptr->image_data_len <= cache_ptr->image_len);
assert(cache_ptr->num_entries_in_image > 0);

/* Reconstruct entries in image */
image_len = cache_ptr->image_len;
for (u = 0; u < cache_ptr->num_entries_in_image; u++) {
/* Create the prefetched entry described by the ith
* entry in cache_ptr->image_entrise.
Expand Down
Loading