summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5O.c9
-rw-r--r--src/H5Ocache.c9
-rw-r--r--src/H5Oprivate.h10
-rw-r--r--test/gen_bogus.c14
-rw-r--r--test/ohdr.c42
-rw-r--r--test/tbogus.h5bin1944 -> 2216 bytes
6 files changed, 62 insertions, 22 deletions
diff --git a/src/H5O.c b/src/H5O.c
index d0ace29..6b9852b 100644
--- a/src/H5O.c
+++ b/src/H5O.c
@@ -44,6 +44,9 @@
#include "H5Iprivate.h" /* IDs */
#include "H5Lprivate.h" /* Links */
#include "H5MFprivate.h" /* File memory management */
+#ifdef H5O_ENABLE_BOGUS
+#include "H5MMprivate.h" /* Memory management */
+#endif /* H5O_ENABLE_BOGUS */
#include "H5Opkg.h" /* Object headers */
#include "H5SMprivate.h" /* Shared object header messages */
@@ -196,10 +199,10 @@ H5O_init_interface(void)
FUNC_ENTER_NOAPI_NOINIT_NOERR
/* H5O interface sanity checks */
- HDassert(H5O_MSG_TYPES == NELMTS(H5O_msg_class_g));
- HDassert(sizeof(H5O_fheap_id_t) == H5O_FHEAP_ID_LEN);
+ HDcompile_assert(H5O_MSG_TYPES == NELMTS(H5O_msg_class_g));
+ HDcompile_assert(sizeof(H5O_fheap_id_t) == H5O_FHEAP_ID_LEN);
- HDassert(H5O_UNKNOWN_ID < H5O_MSG_TYPES);
+ HDcompile_assert(H5O_UNKNOWN_ID < H5O_MSG_TYPES);
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5O_init_interface() */
diff --git a/src/H5Ocache.c b/src/H5Ocache.c
index db1bd1f..203d0fc 100644
--- a/src/H5Ocache.c
+++ b/src/H5Ocache.c
@@ -1130,7 +1130,7 @@ H5O__chunk_deserialize(H5O_t *oh, haddr_t addr, size_t len, const uint8_t *image
id = *chunk_image++;
/* Check for unknown message ID getting encoded in file */
- if(id == H5O_UNKNOWN_ID)
+ if(id >= H5O_UNKNOWN_ID)
HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "'unknown' message ID encoded in file?!?")
/* Message size */
@@ -1218,9 +1218,10 @@ H5O__chunk_deserialize(H5O_t *oh, haddr_t addr, size_t len, const uint8_t *image
/* Set message to "unknown" class */
oh->mesg[mesgno].type = H5O_msg_class_g[H5O_UNKNOWN_ID];
- /* Check for "fail if unknown" message flag */
- if((udata->file_intent & H5F_ACC_RDWR) &&
- (flags & H5O_MSG_FLAG_FAIL_IF_UNKNOWN_AND_OPEN_FOR_WRITE))
+ /* Check for "fail if unknown" message flags */
+ if(((udata->file_intent & H5F_ACC_RDWR) &&
+ (flags & H5O_MSG_FLAG_FAIL_IF_UNKNOWN_AND_OPEN_FOR_WRITE))
+ || (flags & H5O_MSG_FLAG_FAIL_IF_UNKNOWN_ALWAYS))
HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "unknown message with 'fail if unknown' flag found")
/* Check for "mark if unknown" message flag, etc. */
else if((flags & H5O_MSG_FLAG_MARK_IF_UNKNOWN) &&
diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h
index 92d0107..dbe74f7 100644
--- a/src/H5Oprivate.h
+++ b/src/H5Oprivate.h
@@ -75,7 +75,8 @@ typedef struct H5O_t H5O_t;
#define H5O_MSG_FLAG_MARK_IF_UNKNOWN 0x10u
#define H5O_MSG_FLAG_WAS_UNKNOWN 0x20u
#define H5O_MSG_FLAG_SHAREABLE 0x40u
-#define H5O_MSG_FLAG_BITS (H5O_MSG_FLAG_CONSTANT|H5O_MSG_FLAG_SHARED|H5O_MSG_FLAG_DONTSHARE|H5O_MSG_FLAG_FAIL_IF_UNKNOWN_AND_OPEN_FOR_WRITE|H5O_MSG_FLAG_MARK_IF_UNKNOWN|H5O_MSG_FLAG_WAS_UNKNOWN|H5O_MSG_FLAG_SHAREABLE)
+#define H5O_MSG_FLAG_FAIL_IF_UNKNOWN_ALWAYS 0x80u
+#define H5O_MSG_FLAG_BITS (H5O_MSG_FLAG_CONSTANT|H5O_MSG_FLAG_SHARED|H5O_MSG_FLAG_DONTSHARE|H5O_MSG_FLAG_FAIL_IF_UNKNOWN_AND_OPEN_FOR_WRITE|H5O_MSG_FLAG_MARK_IF_UNKNOWN|H5O_MSG_FLAG_WAS_UNKNOWN|H5O_MSG_FLAG_SHAREABLE|H5O_MSG_FLAG_FAIL_IF_UNKNOWN_ALWAYS)
/* Flags for updating messages */
#define H5O_UPDATE_TIME 0x01u
@@ -84,6 +85,9 @@ typedef struct H5O_t H5O_t;
/* Hash value constants */
#define H5O_HASH_SIZE 32
+/* Enable reading/writing "bogus" messages */
+/* #define H5O_ENABLE_BOGUS */
+
/* ========= Object Creation properties ============ */
#define H5O_CRT_ATTR_MAX_COMPACT_NAME "max compact attr" /* Max. # of attributes to store compactly */
#define H5O_CRT_ATTR_MIN_DENSE_NAME "min dense attr" /* Min. # of attributes to store densely */
@@ -196,7 +200,6 @@ typedef struct H5O_copy_t {
#define H5O_UNKNOWN_ID 0x0018 /* Placeholder message ID for unknown message. */
/* (this should never exist in a file) */
-
/* Shared object message types.
* Shared objects can be committed, in which case the shared message contains
* the location of the object header that holds the message, or shared in the
@@ -439,9 +442,6 @@ typedef struct H5O_layout_t {
H5O_storage_t storage; /* Information for storing dataset elements */
} H5O_layout_t;
-/* Enable reading/writing "bogus" messages */
-/* #define H5O_ENABLE_BOGUS */
-
#ifdef H5O_ENABLE_BOGUS
/*
* "Bogus" Message.
diff --git a/test/gen_bogus.c b/test/gen_bogus.c
index df1e81f..e9ce686 100644
--- a/test/gen_bogus.c
+++ b/test/gen_bogus.c
@@ -61,7 +61,7 @@ int main(void)
if((did = H5Dcreate2(fid, "/Dataset1", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto error;
if(H5Dclose(did) < 0) goto error;
- /* Set "fail if unknown" message flag for bogus message */
+ /* Set "fail if unknown and open for write" message flag for bogus message */
bogus_flags = H5O_MSG_FLAG_FAIL_IF_UNKNOWN_AND_OPEN_FOR_WRITE;
if(H5Pset(dcpl, H5O_BOGUS_MSG_FLAGS_NAME, &bogus_flags) < 0) goto error;
@@ -69,12 +69,20 @@ int main(void)
if((did = H5Dcreate2(fid, "/Dataset2", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto error;
if(H5Dclose(did) < 0) goto error;
+ /* Set "fail if unknown always" message flag for bogus message */
+ bogus_flags = H5O_MSG_FLAG_FAIL_IF_UNKNOWN_ALWAYS;
+ if(H5Pset(dcpl, H5O_BOGUS_MSG_FLAGS_NAME, &bogus_flags) < 0) goto error;
+
+ /* Create third dataset, with "fail if unknown always" message flag */
+ if((did = H5Dcreate2(fid, "/Dataset3", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto error;
+ if(H5Dclose(did) < 0) goto error;
+
/* Set "mark if unknown" message flag for bogus message */
bogus_flags = H5O_MSG_FLAG_MARK_IF_UNKNOWN;
if(H5Pset(dcpl, H5O_BOGUS_MSG_FLAGS_NAME, &bogus_flags) < 0) goto error;
- /* Create second dataset, with "mark if unknown" message flag */
- if((did = H5Dcreate2(fid, "/Dataset3", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto error;
+ /* Create fourth dataset, with "mark if unknown" message flag */
+ if((did = H5Dcreate2(fid, "/Dataset4", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto error;
if(H5Dclose(did) < 0) goto error;
/* Close dataset creation property list */
diff --git a/test/ohdr.c b/test/ohdr.c
index 1ba2b10..45f2238 100644
--- a/test/ohdr.c
+++ b/test/ohdr.c
@@ -665,7 +665,9 @@ main(void)
PASSED();
- /* Test reading datasets with undefined object header messages */
+ /* Test reading datasets with undefined object header messages
+ * and the various "fail/mark if unknown" object header message flags
+ */
HDputs("Accessing objects with unknown header messages:");
{
hid_t file2; /* File ID for 'bogus' object file */
@@ -687,7 +689,7 @@ main(void)
PASSED();
- TESTING("object with unknown header message & 'fail if unknown and open for write' flag set");
+ TESTING("object in r/o file with unknown header message & 'fail if unknown and open for write' flag set");
/* Open the dataset with the unknown header message, and "fail if unknown and open for write" flag */
if((dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT)) < 0)
@@ -697,10 +699,23 @@ main(void)
PASSED();
+ TESTING("object in r/o file with unknown header message & 'fail if unknown always' flag set");
+
+ /* Attempt to open the dataset with the unknown header message, and "fail if unknown always" flag */
+ H5E_BEGIN_TRY {
+ dset = H5Dopen2(file2, "/Dataset3", H5P_DEFAULT);
+ } H5E_END_TRY;
+ if(dset >= 0) {
+ H5Dclose(dset);
+ TEST_ERROR
+ } /* end if */
+
+ PASSED();
+
TESTING("object with unknown header message & 'mark if unknown' flag set");
/* Copy object with "mark if unknown" flag on message into file that can be modified */
- if(H5Ocopy(file2, "/Dataset3", file, "/Dataset3", H5P_DEFAULT, H5P_DEFAULT) < 0)
+ if(H5Ocopy(file2, "/Dataset4", file, "/Dataset4", H5P_DEFAULT, H5P_DEFAULT) < 0)
TEST_ERROR
/* Close the file we created (to flush changes to file) */
@@ -712,7 +727,7 @@ main(void)
TEST_ERROR
/* Open the dataset with the "mark if unknown" message */
- if((dset = H5Dopen2(file, "/Dataset3", H5P_DEFAULT)) < 0)
+ if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0)
TEST_ERROR
/* Check that the "unknown" message was _NOT_ marked */
@@ -732,7 +747,7 @@ main(void)
TEST_ERROR
/* Open the dataset with the "mark if unknown" message */
- if((dset = H5Dopen2(file, "/Dataset3", H5P_DEFAULT)) < 0)
+ if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0)
TEST_ERROR
/* Create data space */
@@ -764,7 +779,7 @@ main(void)
TEST_ERROR
/* Re-open the dataset with the "mark if unknown" message */
- if((dset = H5Dopen2(file, "/Dataset3", H5P_DEFAULT)) < 0)
+ if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0)
TEST_ERROR
/* Check that the "unknown" message was marked */
@@ -785,7 +800,7 @@ main(void)
if((file2 = H5Fopen(testfile, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
TEST_ERROR
- TESTING("object with unknown header message & 'fail if unknown and open for write' flag set");
+ TESTING("object in r/w file with unknown header message & 'fail if unknown and open for write' flag set");
/* Attempt to open the dataset with the unknown header message, and "fail if unknown and open for write" flag */
H5E_BEGIN_TRY {
@@ -796,6 +811,19 @@ main(void)
TEST_ERROR
} /* end if */
+ PASSED();
+
+ TESTING("object in r/w file with unknown header message & 'fail if unknown always' flag set");
+
+ /* Attempt to open the dataset with the unknown header message, and "fail if unknown always" flag */
+ H5E_BEGIN_TRY {
+ dset = H5Dopen2(file2, "/Dataset3", H5P_DEFAULT);
+ } H5E_END_TRY;
+ if(dset >= 0) {
+ H5Dclose(dset);
+ TEST_ERROR
+ } /* end if */
+
/* Close the file with the bogus objects */
if(H5Fclose(file2) < 0)
TEST_ERROR
diff --git a/test/tbogus.h5 b/test/tbogus.h5
index 906921c..875fbd8 100644
--- a/test/tbogus.h5
+++ b/test/tbogus.h5
Binary files differ