There seem to be a problem reading fixed length strings that are not
null-terminated (H5T_STR_NULLPAD) with the
H5::DataSet::read(H5std_string...) method. What happens is the following:
1: H5::DataSet::read(H5std_string...) calls DataSet::p_read_fixed_len.
2: A new "strg_C" string buffer of lenght attr_size+1 is allocated in
DataSet::p_read_fixed_len. This buffer is neither cleared nor
null-terminated in any way.
3: The "strg_C" buffer is filled with data from a H5Dread call. H5Dread
will only copy in actual string data, and _not_ zero-termination for
H5T_STR_NULLPAD strings. This leaves "strg_C" without any zero-termination.
4: "strg_C" is assigned to the std::string output. This operation is
nondeterministic, and will generate output of arbitrary length,
depending on memory content.
I believe that the above problem can be resolved by clearing the
"strg_C" immediately after allocation. This will ensure that the string
is always zero-terminated, independent of actual length. A patch that
attempt to fix this issue is attached.
Best regards,
Fredrik Orderud
Index: c++/src/H5DataSet.cpp
===================================================================
--- c++/src/H5DataSet.cpp (revision 24722)
+++ c++/src/H5DataSet.cpp (working copy)
@@ -651,6 +651,7 @@
char *strg_C = NULL;
strg_C = new char [(size_t)attr_size+1];
+ memset(strg_C, 0, attr_size+1); // clear buffer in case string is not
stored null-terminated
herr_t ret_value = H5Dread(id, mem_type_id, mem_space_id,
file_space_id, xfer_plist_id, strg_C);
if( ret_value < 0 )
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org