BUG: AppendFile saves references to objects outside the appended object under the wrong ID

Đang mở
#1,960 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
backend, databases

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug

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

  1. Create a DataStructure with a top-level Triangle Geometry Triangle Geometry whose Vertices and Faces arrays are its children, and a top-level group Other.
  2. Move Triangle Geometry/Vertices into Other, as the Move Data filter does. The geometry still references the vertex array.
  3. Write an empty DataStructure to a new .dream3d file, then append Triangle Geometry to it with AppendFile.
  4. 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, and AppendFile removes them and their references from its copy before pruning. Other outside references are unchanged by that PR.
  • resetIds is called only by AppendFile. A full DREAM3D::WriteFile writes every object with its own ID, so it is not affected.
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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của BlueQuartzSoftware/simplnx

Tất cả issue của BlueQuartzSoftware/simplnx

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.