BUG: WriteObjectAttributes ignores failed attribute writes and reports success
Maintainer thường phản hồi trong vòng 6 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Start with IDataIO::WriteObjectAttributes in src/simplnx/DataStructure/IO/HDF5/IDataIO.cpp and the existing checks in BaseGroupIO::WriteBaseGroupData; the issue provides a focused failure reproduction in test/H5Test.cpp. Then inspect the related NextId and createGroup() writes named in the report. Done when failed writes return errors, and the supplied regression test plus the HDF5 and .dream3d write tests pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem
IDataIO::WriteObjectAttributes writes three HDF5 attributes for every DataObject: ObjectType, ObjectId and Importable. The function ignores the Result of each write. It always returns success.
Expected: the writer returns an error when an attribute write fails.
Actual: the writer returns success. The .dream3d file is reported as written, but required attributes are missing. When the file is read again, a dataset (for example a DataArray) with no Importable attribute is skipped by the reader, so its data is lost without an error; a group with no Importable attribute fails the read.
Found at commit 01809c236527ba812055cd6ab46e142317670c77.
Steps to Reproduce
- Build
simplnx_testat commit01809c236527ba812055cd6ab46e142317670c77. - Create an HDF5 file that has a
DataStructuregroup and a child group namedGroup. - Open that file again with
HDF5::FileIO::ReadFile(read-only). Every attribute creation on this handle fails. - Call
HDF5::DataStructureWriter::WriteFilewith aDataStructurethat holds oneDataGroupnamedGroup. - Check the returned
Result. It is valid. The attributesObjectType,ObjectIdandImportabledo not exist on the group.
The verification test below does these steps. It uses a read-only handle only to make the attribute creation fail. The groups already exist, so no group creation fails.
Cause
WriteObjectAttributes calls writeStringAttribute and writeScalarAttribute three times. It does not read the returned Result values. It then returns {}, which is success.
Result<> IDataIO::WriteObjectAttributes(DataStructureWriter& dataStructureWriter, const DataObject& dataObject, object_writer_type& objectWriter, bool importable)
{
std::string dataTypeName = dataObject.getTypeName();
objectWriter.writeStringAttribute(Constants::k_ObjectTypeTag, dataTypeName);
objectWriter.writeScalarAttribute(Constants::k_ObjectIdTag, dataObject.getId());
int32 value = (importable ? 1 : 0);
objectWriter.writeScalarAttribute(Constants::k_ImportableTag, value);
// Add to DataStructureWriter for use in linking
dataStructureWriter.addWriter(objectWriter, dataObject.getId());
return {};
}
The caller code already checks the return value of WriteObjectAttributes (for example in BaseGroupIO::WriteBaseGroupData, L23-L27). Because the function never returns an error, these checks have no effect.
Related code with the same pattern. This part was confirmed by reading only. It was not reproduced.
- The
NextIdattribute write result is ignored inDataStructureWriter::writeDataStructure(https://github.com/BlueQuartzSoftware/simplnx/blob/01809c236527ba812055cd6ab46e142317670c77/src/simplnx/DataStructure/IO/HDF5/DataStructureWriter.cpp#L196). The other writer path at L115 of the same file does check the result. BaseGroupIO::WriteBaseGroupData(https://github.com/BlueQuartzSoftware/simplnx/blob/01809c236527ba812055cd6ab46e142317670c77/src/simplnx/DataStructure/IO/HDF5/BaseGroupIO.cpp#L21-L23) andDataGroupIO::writeData(https://github.com/BlueQuartzSoftware/simplnx/blob/01809c236527ba812055cd6ab46e142317670c77/src/simplnx/DataStructure/IO/HDF5/DataGroupIO.cpp#L32) callcreateGroup()and do not check that the returned group is valid.
Verification Unit Test
File: test/H5Test.cpp (append at the end of the file).
TEST_CASE("DataStructureWriter: failed object attribute writes fail the write", "[DataStructureWriter][HDF5]")
{
// Fault injection: the DataStructure group and the object's group already exist,
// so GroupIO::createGroup() opens them successfully, but the file is opened
// read-only, so every attribute write (ObjectType, ObjectId, Importable) fails.
const fs::path filePath = GetDataDir() / "attribute_write_failure.h5";
const std::string groupName = "Group";
{
auto fileWriter = HDF5::FileIO::WriteFile(filePath);
REQUIRE(fileWriter.isValid());
auto dataStructureGroup = fileWriter.createGroup(nx::core::Constants::k_DataStructureTag);
REQUIRE(dataStructureGroup.isValid());
auto objectGroup = dataStructureGroup.createGroup(groupName);
REQUIRE(objectGroup.isValid());
}
DataStructure dataStructure;
REQUIRE(DataGroup::Create(dataStructure, groupName) != nullptr);
Result<> writeResult;
{
auto readOnlyFile = HDF5::FileIO::ReadFile(filePath);
REQUIRE(readOnlyFile.isValid());
writeResult = HDF5::DataStructureWriter::WriteFile(dataStructure, readOnlyFile);
}
// Confirm the injected fault took effect: none of the object attributes were written.
{
auto fileReader = HDF5::FileIO::ReadFile(filePath);
REQUIRE(fileReader.isValid());
auto objectGroup = fileReader.openGroup(nx::core::Constants::k_DataStructureTag).openGroup(groupName);
REQUIRE(objectGroup.isValid());
REQUIRE_FALSE(objectGroup.hasAttribute(nx::core::Constants::k_ObjectTypeTag));
REQUIRE_FALSE(objectGroup.hasAttribute(nx::core::Constants::k_ObjectIdTag));
REQUIRE_FALSE(objectGroup.hasAttribute(nx::core::Constants::k_ImportableTag));
}
// Expected: the writer reports the failed attribute writes instead of success.
SIMPLNX_RESULT_REQUIRE_INVALID(writeResult);
}
Build and run only this test. Use the build directory of a configured simplnx build tree.
cmake --build <build-dir> -j --target simplnx_test
cd <build-dir> && ctest -R "^DataStructureWriter: failed object attribute writes fail the write$" --output-on-failure
Output at commit 01809c236527ba812055cd6ab46e142317670c77 (HDF5 diagnostic lines removed):
HDF5-DIAG: ... H5Acreate2(): unable to synchronously create attribute
... H5VL__native_attr_create(): no write intent on file
test/H5Test.cpp:1543: FAILED:
REQUIRE( simplnxCheckedResult.invalid() )
with expansion:
false
test cases: 1 | 0 passed | 1 failed
assertions: 11 | 10 passed | 1 failed
The 10 assertions that pass confirm that the fault took effect. No attribute was written, and the write still returned success.
Proposed Fix
- In
IDataIO::WriteObjectAttributes, keep eachResultand return the first invalid one before theaddWritercall. Keep the existing behavior for the success path.
Result<> IDataIO::WriteObjectAttributes(DataStructureWriter& dataStructureWriter, const DataObject& dataObject, object_writer_type& objectWriter, bool importable)
{
Result<> result = objectWriter.writeStringAttribute(Constants::k_ObjectTypeTag, dataObject.getTypeName());
if(result.invalid())
{
return result;
}
result = objectWriter.writeScalarAttribute(Constants::k_ObjectIdTag, dataObject.getId());
if(result.invalid())
{
return result;
}
result = objectWriter.writeScalarAttribute(Constants::k_ImportableTag, static_cast<int32>(importable ? 1 : 0));
if(result.invalid())
{
return result;
}
dataStructureWriter.addWriter(objectWriter, dataObject.getId());
return {};
}
- In
DataStructureWriter::writeDataStructure, check theResultof theNextIdwrite. - In
BaseGroupIO::WriteBaseGroupDataandDataGroupIO::writeData, return an error whencreateGroup()returns an invalid group.DataGroupIO::writeDataalso creates a group that it does not use before it callsWriteBaseGroupData. Remove that unused call when this code is changed.
This change makes more writes fail in cases that now pass silently. Run the HDF5 and .dream3d write tests after the change. Other *IO classes that call WriteObjectAttributes get the new error path with no further change.
Notes
- The reader behavior was confirmed by reading the code, not by a test: for a dataset, a missing
Importableattribute leavesimportableat 0 and the object is skipped (DataStructureReader.cpp#L184-L194); for a group, the failed attribute read is returned as an error (#L144-L150). - The attribute write functions of the HDF5 wrapper return a
Result. Check each overload before the fix.
- Ngôn ngữ chính
- C++
- Star
- 18
- Fork
- 15
- Merge trung bình
- 4 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 42
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của BlueQuartzSoftware/simplnx
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
BlueQuartzSoftware/simplnx#1987 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
BlueQuartzSoftware/simplnx#1980 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
Testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
BlueQuartzSoftware/simplnx#1979 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
BlueQuartzSoftware/simplnx#1978 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
BlueQuartzSoftware/simplnx#1945 ·
Maintainer thường phản hồi trong vòng 6 ngày
Tất cả issue của BlueQuartzSoftware/simplnx
Issue tương tự
-
bug triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
26.04 bug dark-mode Easy Hack impress symptom: visual
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
CollaboraOnline/online#16421 · 1 bình luận ·
-
area/cs bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
ydb-platform/ydb#59881 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation enhancement lua server
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100