summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5SMcache.c57
-rwxr-xr-xsrc/H5SMpkg.h6
2 files changed, 50 insertions, 13 deletions
diff --git a/src/H5SMcache.c b/src/H5SMcache.c
index 70b7b56..a74926f 100644
--- a/src/H5SMcache.c
+++ b/src/H5SMcache.c
@@ -125,9 +125,10 @@ H5SM_flush_table(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_ma
if (table->cache_info.is_dirty) {
uint8_t buf[H5F_TABLEBUF_SIZE]; /* Temporary buffer */ /* JAMES This is big. Do I need to use H5FL_BLK_MALLOC instead? */
- uint8_t *p; /* Pointer into raw data buffer */
- size_t size; /* Header size on disk */
- int x; /* Counter variable */
+ uint8_t *p; /* Pointer into raw data buffer */
+ size_t size; /* Header size on disk */
+ uint32_t computed_chksum; /* Computed metadata checksum value */
+ int x; /* Counter variable */
/* Encode the master table and all of the index headers as one big blob */
size = H5SM_TABLE_SIZE(f) + (H5SM_INDEX_HEADER_SIZE(f) * table->num_indexes);
@@ -154,7 +155,9 @@ H5SM_flush_table(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_ma
H5F_addr_encode(f, &p, table->indexes[x].heap_addr); /* Address of the index's heap */
}
- /* JAMES: do checksum */
+ /* Compute checksum on buffer */
+ computed_chksum = H5_checksum_metadata(buf, (size - H5SM_SIZEOF_CHECKSUM), 0);
+ UINT32ENCODE(p, computed_chksum);
/* Write the table to disk */
HDassert((size_t)(p - buf) == size);
@@ -190,10 +193,12 @@ done:
static H5SM_master_table_t *
H5SM_load_table(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, H5SM_master_table_t *table)
{
- size_t table_size; /* Size of SOHM master table on disk */
- uint8_t *buf=NULL; /* Reading buffer */
- const uint8_t *p; /* Pointer into input buffer */
- uint8_t x; /* Counter variable for index headers */
+ size_t table_size; /* Size of SOHM master table on disk */
+ uint8_t *buf=NULL; /* Reading buffer */
+ const uint8_t *p; /* Pointer into input buffer */
+ uint32_t stored_chksum; /* Stored metadata checksum value */
+ uint32_t computed_chksum; /* Computed metadata checksum value */
+ uint8_t x; /* Counter variable for index headers */
H5SM_master_table_t *ret_value;
FUNC_ENTER_NOAPI(H5SM_load_table, NULL)
@@ -228,7 +233,7 @@ H5SM_load_table(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1
/* Don't count the checksum in the table size yet, since it comes after
* all of the index headers
*/
- HDassert((size_t)(p - buf) == H5SM_TABLE_SIZE(f) /* JAMES: minus checksum size */);
+ HDassert((size_t)(p - buf) == H5SM_TABLE_SIZE(f) - H5SM_SIZEOF_CHECKSUM);
/* Allocate space for the index headers in memory*/
if(NULL == (table->indexes = H5FL_ARR_MALLOC(H5SM_index_header_t, table->num_indexes)))
@@ -248,8 +253,18 @@ H5SM_load_table(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1
}
/* Read in checksum */
+ UINT32DECODE(p, stored_chksum);
+ /* Sanity check */
HDassert((size_t)(p - buf) == table_size);
+
+ /* Compute checksum on entire header */
+ computed_chksum = H5_checksum_metadata(buf, (table_size - H5SM_SIZEOF_CHECKSUM), 0);
+
+ /* Verify checksum */
+ if(stored_chksum != computed_chksum)
+ HGOTO_ERROR(H5E_SOHM, H5E_BADVALUE, NULL, "incorrect metadata checksum for shared message table");
+
ret_value = table;
done:
@@ -387,6 +402,7 @@ H5SM_flush_list(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_lis
uint8_t buf[H5F_LISTBUF_SIZE]; /* Temporary buffer */ /* JAMES Do I need to use H5FL_BLK_MALLOC instead? */
uint8_t *p; /* Pointer into raw data buffer */
size_t size; /* Header size on disk */
+ uint32_t computed_chksum; /* Computed metadata checksum value */
hsize_t x;
/* JAMES: consider only writing as many messages as necessary, and then adding a
@@ -416,6 +432,10 @@ H5SM_flush_list(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_lis
}
}
+ /* Compute checksum on buffer */
+ computed_chksum = H5_checksum_metadata(buf, (size - H5SM_SIZEOF_CHECKSUM), 0);
+ UINT32ENCODE(p, computed_chksum);
+
/* Write the list to disk */
HDassert((size_t)(p - buf) == size);
if(H5F_block_write(f, H5FD_MEM_SOHM, addr, size, dxpl_id, buf) < 0)
@@ -454,6 +474,8 @@ H5SM_load_list(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1,
size_t size; /* Size of SOHM list on disk */
uint8_t *buf = NULL; /* Reading buffer */
uint8_t *p; /* Pointer into input buffer */
+ uint32_t stored_chksum; /* Stored metadata checksum value */
+ uint32_t computed_chksum; /* Computed metadata checksum value */
hsize_t x; /* Counter variable for messages in list */
H5SM_list_t *ret_value=NULL;
@@ -502,6 +524,21 @@ H5SM_load_list(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1,
UINT64DECODE(p, list->messages[x].fheap_id); /* Get the heap ID for the message */
}
+ /* Read in checksum */
+ UINT32DECODE(p, stored_chksum);
+
+ /* Sanity check */
+ HDassert((size_t)(p - buf) == size);
+
+
+ /* Compute checksum on entire header */
+ computed_chksum = H5_checksum_metadata(buf, (size - H5SM_SIZEOF_CHECKSUM), 0);
+
+ /* Verify checksum */
+ if(stored_chksum != computed_chksum)
+ HGOTO_ERROR(H5E_SOHM, H5E_BADVALUE, NULL, "incorrect metadata checksum for shared message list");
+
+
/* Initialize the rest of the array */
for(x=header->num_messages; x<header->list_to_btree; x++)
{
@@ -510,8 +547,6 @@ H5SM_load_list(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1,
list->messages[x].hash = H5O_HASH_UNDEF;
}
- HDassert((size_t)(p - buf) == size);
-
ret_value = list;
done:
if(buf)
diff --git a/src/H5SMpkg.h b/src/H5SMpkg.h
index 51c6c1f..c62e748 100755
--- a/src/H5SMpkg.h
+++ b/src/H5SMpkg.h
@@ -35,6 +35,7 @@
#define H5SM_LIST_SIZEOF_MAGIC 4
#define H5SM_TABLE_MAGIC "SMTB"
#define H5SM_TABLE_SIZEOF_MAGIC 4
+#define H5SM_SIZEOF_CHECKSUM 4
#define H5SM_MASTER_TABLE_VERSION 0 /* Version of the Shared Object Header Message Master Table*/
@@ -44,7 +45,7 @@
#define H5SM_TABLE_SIZE(f) ( H5SM_TABLE_SIZEOF_MAGIC \
+ 1 /* Table version */ \
- + 0/* JAMES checksum */) /* Checksum */
+ + H5SM_SIZEOF_CHECKSUM) /* Checksum */
#define H5SM_INDEX_HEADER_SIZE(f) (1 /* Whether index is a list or B-tree */ \
+ 2 /* Type of messages stored in the index */ \
@@ -56,7 +57,8 @@
/* JAMES: add checksum? */
#define H5SM_LIST_SIZE(f, num_mesg) H5SM_LIST_SIZEOF_MAGIC \
+ 1 /* List version */ \
- + (H5SM_SOHM_ENTRY_SIZE(f) * num_mesg)
+ + (H5SM_SOHM_ENTRY_SIZE(f) * num_mesg) \
+ + H5SM_SIZEOF_CHECKSUM /* Checksum */
#define H5SM_MAX_INDEXES 8
#define H5SM_MAX_LIST_ELEMS 1000