116116/* Helper routines */
117117static size_t H5C__cache_image_block_entry_header_size (const H5F_t * f );
118118static size_t H5C__cache_image_block_header_size (const H5F_t * f );
119- static herr_t H5C__decode_cache_image_header (const H5F_t * f , H5C_t * cache_ptr , const uint8_t * * buf );
119+ static herr_t H5C__decode_cache_image_header (const H5F_t * f , H5C_t * cache_ptr , const uint8_t * * buf , size_t buf_size );
120120#ifndef NDEBUG /* only used in assertions */
121121static herr_t H5C__decode_cache_image_entry (const H5F_t * f , const H5C_t * cache_ptr , const uint8_t * * buf ,
122122 unsigned entry_num );
@@ -297,7 +297,7 @@ H5C__construct_cache_image_buffer(H5F_t *f, H5C_t *cache_ptr)
297297 /* needed for sanity checks */
298298 fake_cache_ptr -> image_len = cache_ptr -> image_len ;
299299 q = (const uint8_t * )cache_ptr -> image_buffer ;
300- status = H5C__decode_cache_image_header (f , fake_cache_ptr , & q );
300+ status = H5C__decode_cache_image_header (f , fake_cache_ptr , & q , cache_ptr -> image_len + 1 );
301301 assert (status >= 0 );
302302
303303 assert (NULL != p );
@@ -1267,7 +1267,7 @@ H5C__cache_image_block_header_size(const H5F_t *f)
12671267 *-------------------------------------------------------------------------
12681268 */
12691269static herr_t
1270- H5C__decode_cache_image_header (const H5F_t * f , H5C_t * cache_ptr , const uint8_t * * buf )
1270+ H5C__decode_cache_image_header (const H5F_t * f , H5C_t * cache_ptr , const uint8_t * * buf , size_t buf_size )
12711271{
12721272 uint8_t version ;
12731273 uint8_t flags ;
@@ -1288,7 +1288,7 @@ H5C__decode_cache_image_header(const H5F_t *f, H5C_t *cache_ptr, const uint8_t *
12881288 p = * buf ;
12891289
12901290 /* Ensure buffer has enough data for signature comparison */
1291- if (H5_IS_BUFFER_OVERFLOW (p , H5C__MDCI_BLOCK_SIGNATURE_LEN , * buf + cache_ptr -> image_len ))
1291+ if (H5_IS_BUFFER_OVERFLOW (p , H5C__MDCI_BLOCK_SIGNATURE_LEN , * buf + buf_size ))
12921292 HGOTO_ERROR (H5E_CACHE , H5E_OVERFLOW , FAIL , "Insufficient buffer size for signature" );
12931293
12941294 /* Check signature */
@@ -2390,7 +2390,7 @@ H5C__reconstruct_cache_contents(H5F_t *f, H5C_t *cache_ptr)
23902390
23912391 /* Decode metadata cache image header */
23922392 p = (uint8_t * )cache_ptr -> image_buffer ;
2393- if (H5C__decode_cache_image_header (f , cache_ptr , & p ) < 0 )
2393+ if (H5C__decode_cache_image_header (f , cache_ptr , & p , cache_ptr -> image_len + 1 ) < 0 )
23942394 HGOTO_ERROR (H5E_CACHE , H5E_CANTDECODE , FAIL , "cache image header decode failed" );
23952395 assert ((size_t )(p - (uint8_t * )cache_ptr -> image_buffer ) < cache_ptr -> image_len );
23962396
0 commit comments