BUG: AppendFile saves references to objects outside the appended object under the wrong ID
维护者通常 6 天内回复
还没有人认领这个 Issue。
评估
调研方向
Read src/simplnx/DataStructure/IO/HDF5/DataStructureWriter.cpp around AppendFile and the ID remapping in src/simplnx/Utilities/DataObjectUtilities.hpp; the issue also identifies test/H5Test.cpp and provides a reproducing test. Run the listed ctest command to confirm the failure. Done means appending either reports an error naming an outside reference or stores a valid reference, as the test permits; the appropriate behavior for callers that move arrays out of a geometry remains open.
由索引模型根据 Issue 内容生成。
描述
Problem
DataStructureWriter::AppendFile (DREAM3D::AppendFile, Python append_to_dream3d_file) can save a geometry whose reference names the wrong object. When the appended object references an object outside itself, the saved reference keeps the old ID. After the appended object is renumbered, that ID can belong to another saved object.
Expected: the append returns an error that names the outside reference, or the saved reference names the referenced object. Actual: the append reports success, and the reloaded geometry's Vertex List ID names its Face list (Triangle Geometry/Faces).
Occurs on develop 32ceb10b9.
Steps to Reproduce
- Create a DataStructure with a top-level Triangle Geometry
Triangle GeometrywhoseVerticesandFacesarrays are its children, and a top-level groupOther. - Move
Triangle Geometry/VerticesintoOther, as the Move Data filter does. The geometry still references the vertex array. - Write an empty DataStructure to a new
.dream3dfile, then appendTriangle Geometryto it withAppendFile. - Read the file back. The geometry's Vertex List ID is 2, and object 2 in the file is
Triangle Geometry/Faces.
From Python, the same sequence is a pipeline that ends with Move Data, followed by nx.append_to_dream3d_file(path, data_structure, nx.DataPath(["Triangle Geometry"])). The unit test below reproduces it directly; the Python route was not run.
Cause
AppendFile copies the DataStructure, removes every top-level object except the appended one, and renumbers the copy from the file's NextObjectId (DataStructureWriter.cpp#L103-L113):
DataStructure dataStructureShallowCopy = dataStructure;
for(DataObject* topLevelObject : dataStructureShallowCopy.getTopLevelData())
{
if(topLevelObject->getName() != targetName)
{
dataStructureShallowCopy.removeData(topLevelObject->getId());
}
}
dataStructureShallowCopy.resetIds(nextObjectId);
The vertex array is a child of Other, so the pruning removes it. resetIds builds an old-to-new map only from the objects that remain, and each object then remaps its references through that map. A reference with no entry in the map keeps its old value (DataObjectUtilities.hpp#L47-L56):
if(originalId == updatedId.first && !visited[visitedIndex])
{
visited[visitedIndex] = true;
return updatedId.second;
}
return originalId;
In the test, the geometry is ID 1, the vertices 2, the faces 3 and the group 4. The file's NextObjectId is 1, so the geometry becomes 1 and the faces become 2. The vertex reference stays 2, which now names the faces.
Move Data (MoveDataFilter.cpp#L49) accepts any object, including a geometry's own vertex, edge or face array, so a pipeline can create such an outside reference.
Verification Unit Test
File: test/H5Test.cpp (append at the end; it also needs #include "simplnx/Filter/Actions/MoveDataAction.hpp").
TEST_CASE("DataStructureWriter: AppendFile does not store a reference to an object outside the appended object", "[simplnx][HDF5][AppendFile]")
{
const fs::path filePath = GetDataDir() / "AppendFileOutsideReference.dream3d";
// An empty file: renumbering the appended object starts at ID 1.
DataStructure baseDataStructure;
const auto baseWrite = HDF5::DataStructureWriter::WriteFile(baseDataStructure, filePath);
SIMPLNX_RESULT_REQUIRE_VALID(baseWrite);
// Geometry ID 1, vertices ID 2, faces ID 3, group ID 4.
DataStructure dataStructure;
dataStructure.setNextId(1);
auto* geometryPtr = TriangleGeom::Create(dataStructure, "Triangle Geometry");
REQUIRE(geometryPtr != nullptr);
const DataPath verticesPath({"Triangle Geometry", "Vertices"});
const DataPath facesPath({"Triangle Geometry", "Faces"});
const auto verticesCreated = ArrayCreationUtilities::CreateArray<float32>(dataStructure, {3}, {3}, verticesPath, IDataAction::Mode::Execute);
SIMPLNX_RESULT_REQUIRE_VALID(verticesCreated);
const auto facesCreated = ArrayCreationUtilities::CreateArray<IGeometry::MeshIndexType>(dataStructure, {1}, {3}, facesPath, IDataAction::Mode::Execute);
SIMPLNX_RESULT_REQUIRE_VALID(facesCreated);
auto& vertices = dataStructure.getDataRefAs<Float32Array>(verticesPath);
auto& faces = dataStructure.getDataRefAs<IGeometry::SharedFaceList>(facesPath);
const std::vector<float32> vertexValues = {0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F};
for(usize index = 0; index < vertexValues.size(); ++index)
{
vertices[index] = vertexValues[index];
}
faces[0] = 0;
faces[1] = 1;
faces[2] = 2;
geometryPtr->setVertices(vertices);
geometryPtr->setFaceList(faces);
REQUIRE(DataGroup::Create(dataStructure, "Other") != nullptr);
// What the Move Data filter does: the vertex array leaves the geometry, and the geometry still references it.
const auto moved = MoveDataAction(verticesPath, DataPath({"Other"})).apply(dataStructure, IDataAction::Mode::Execute);
SIMPLNX_RESULT_REQUIRE_VALID(moved);
REQUIRE(geometryPtr->getVertexListId() == vertices.getId());
const auto appendResult = HDF5::DataStructureWriter::AppendFile(filePath, dataStructure, DataPath({"Triangle Geometry"}));
if(appendResult.invalid())
{
// Rejecting the outside reference is correct behavior.
return;
}
auto readResult = HDF5::DataStructureReader::ReadFile(filePath);
SIMPLNX_RESULT_REQUIRE_VALID(readResult);
const DataStructure& reloaded = readResult.value();
const auto& reloadedGeometry = reloaded.getDataRefAs<TriangleGeom>(DataPath({"Triangle Geometry"}));
const auto vertexListId = reloadedGeometry.getVertexListId();
if(!vertexListId.has_value())
{
return;
}
// A stored vertex reference must name the vertex array, not another object of the file.
const DataObject* namedPtr = reloaded.getData(vertexListId.value());
CAPTURE(vertexListId.value());
CAPTURE(namedPtr == nullptr ? std::string("no object") : namedPtr->getDataPaths().front().toString());
const auto* reloadedVerticesPtr = dynamic_cast<const Float32Array*>(namedPtr);
REQUIRE(reloadedVerticesPtr != nullptr);
for(usize index = 0; index < vertexValues.size(); ++index)
{
CHECK((*reloadedVerticesPtr)[index] == vertexValues[index]);
}
}
Run: ctest --test-dir <build-dir> -R "AppendFile does not store a reference" -j 1 --output-on-failure
Output on develop 32ceb10b9 (Release, macOS):
test/H5Test.cpp:1564: FAILED:
REQUIRE( reloadedVerticesPtr != nullptr )
with expansion:
vertexListId.value() := 2
namedPtr == nullptr ? std::string("no object") : namedPtr->getDataPaths().
front().toString() := "Triangle Geometry/Faces"
Proposed Fix
In DataStructureWriter::AppendFile, before the pruning loop, collect every ID that an object of the appended subtree references (geometry vertex, edge, face, cell and attribute-matrix IDs, and any other checkUpdatedIds reference). For each referenced object outside the subtree, either:
- return a new error that names the appended object, the reference and the outside object's path, or
- clear that reference in the copy, with a warning, so the file stores no ID for it.
The test above accepts either result. Which one is right for callers that move arrays out of a geometry is still open.
Notes
- PR #1919 handles one case of this in
AppendFile: geometry connectivity lists (vertex incidence and element neighbors). The writer no longer saves them, andAppendFileremoves them and their references from its copy before pruning. Other outside references are unchanged by that PR. resetIdsis called only byAppendFile. A fullDREAM3D::WriteFilewrites every object with its own ID, so it is not affected.
- 主要语言
- C++
- 星标
- 18
- 派生
- 15
- 平均合并
- 4 天 23 小时
- 30 天内合并 PR
- 42
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
BlueQuartzSoftware/simplnx 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
BlueQuartzSoftware/simplnx#1987 ·
维护者通常 6 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 74/100
BlueQuartzSoftware/simplnx#1980 ·
维护者通常 6 天内回复
-
Testing
难度 2/5 1-3 小时 新手友好度 62/100
BlueQuartzSoftware/simplnx#1979 ·
维护者通常 6 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 65/100
BlueQuartzSoftware/simplnx#1978 ·
维护者通常 6 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
BlueQuartzSoftware/simplnx#1945 ·
维护者通常 6 天内回复
查看 BlueQuartzSoftware/simplnx 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
HarperFast/rocksdb-js#1118 ·
维护者通常 1 天内回复
-
bug triage
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
26.04 bug dark-mode Easy Hack impress symptom: visual
难度 2/5 1-3 小时 新手友好度 68/100
CollaboraOnline/online#16421 · 1 条评论 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 63/100
telegramdesktop/tdesktop#31653 ·
维护者通常 1 天内回复
-
area/cs bug
难度 2/5 1-3 小时 新手友好度 82/100
ydb-platform/ydb#59881 · 1 条评论 ·
维护者通常 1 天内回复