diff --git a/Framework/DataHandling/src/LoadHelper.cpp b/Framework/DataHandling/src/LoadHelper.cpp index f53b40e5ef4f0bf0964fd08cb86f359d1a1240b2..64e202bbe707fd26ebace2adb7acc9660dfdc673 100644 --- a/Framework/DataHandling/src/LoadHelper.cpp +++ b/Framework/DataHandling/src/LoadHelper.cpp @@ -418,11 +418,22 @@ void LoadHelper::dumpNexusAttributes(NXhandle nxfileID, // Attributes NXname pName; int iLength, iType; + int rank; + int dims[4]; int nbuff = 127; boost::shared_array<char> buff(new char[nbuff + 1]); - while (NXgetnextattr(nxfileID, pName, &iLength, &iType) != NX_EOD) { + while (NXgetnextattra(nxfileID, pName, &rank, dims, &iType) != NX_EOD) { g_log.debug() << indentStr << '@' << pName << " = "; + if (rank > 1) { // mantid only supports single value attributes + throw std::runtime_error( + "Encountered attribute with multi-dimensional array value"); + } + iLength = dims[0]; // to clarify things + if (iType != NX_CHAR && iLength != 1) { + throw std::runtime_error("Encountered attribute with array value"); + } + switch (iType) { case NX_CHAR: { if (iLength > nbuff + 1) { diff --git a/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp b/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp index a7861c6ee6eae7b9ae5eda6f9b3d705226b66c55..4c00a74f53256a2b6e8e58662897f1c86a91fa61 100644 --- a/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp +++ b/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp @@ -18,7 +18,6 @@ #include <boost/shared_ptr.hpp> #include <boost/scoped_array.hpp> #include <Poco/File.h> -//#include <hdf5.h> //This is troublesome on multiple platforms. #include <cstdlib> #include <cstring> @@ -649,15 +648,20 @@ int SaveToSNSHistogramNexus::WriteAttributes(int is_definition) { (void)is_definition; int status, i, attrLen, attrType; + int rank; + int dims[4]; NXname attrName; void *attrBuffer; i = 0; do { - status = NXgetnextattr(inId, attrName, &attrLen, &attrType); + status = NXgetnextattra(inId, attrName, &rank, dims, &attrType); if (status == NX_ERROR) return NX_ERROR; if (status == NX_OK) { + if (rank != 1) + return NX_ERROR; + attrLen = dims[0]; if (strcmp(attrName, "NeXus_version") && strcmp(attrName, "XML_version") && strcmp(attrName, "HDF_version") && strcmp(attrName, "HDF5_Version") && strcmp(attrName, "file_name") && diff --git a/Framework/Nexus/src/NexusClasses.cpp b/Framework/Nexus/src/NexusClasses.cpp index 16d5b88e5c2c7854d50361188b242dd811d15576..62ca8725159c2860255e4b1cf1756d960d09c5f7 100644 --- a/Framework/Nexus/src/NexusClasses.cpp +++ b/Framework/Nexus/src/NexusClasses.cpp @@ -83,12 +83,24 @@ std::string NXObject::name() const { void NXObject::getAttributes() { NXname pName; int iLength, iType; + int rank; + int dims[4]; int nbuff = 127; boost::shared_array<char> buff(new char[nbuff + 1]); - while (NXgetnextattr(m_fileID, pName, &iLength, &iType) != NX_EOD) { + + while (NXgetnextattra(m_fileID, pName, &rank, dims, &iType) != NX_EOD) { // std::cerr<<"--------------------------\n"; // std::cerr<<"name="<<path()<<'\n'; // std::cerr<<pName<<' ' <<iLength<<' '<<iType<<'\n'; + if (rank > 1) { // mantid only supports single value attributes + throw std::runtime_error( + "Encountered attribute with multi-dimensional array value"); + } + iLength = dims[0]; // to clarify things + if (iType != NX_CHAR && iLength != 1) { + throw std::runtime_error("Encountered attribute with array value"); + } + switch (iType) { case NX_CHAR: { if (iLength > nbuff + 1) {