BUG: Reject or safely write TIFFs with negative origins

Đang mở
#1,914 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ó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/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

Hướng nghiên cứu

Start with src/simplnx/Utilities/ImageIO/TiffImageIO.cpp and test/TiffImageIOTest.cpp; the issue identifies the position-tag writes and provides a reproducing test. First run the named signed-origin test and compare its negative-origin result with the positive control. Done means TIFF writes either preserve the requested origin in a supported representation or return an explicit error, with failed finalization unable to publish an incomplete file; verify the affected planes and bookmark slices as described.

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

Mô tả

bug

Problem

Writing a TIFF with a negative X origin can report success while producing a file that cannot be opened. On Windows with libtiff 4.7.1, public simplnx develop at a7dffc440d5da44e013f47a1969db950cbcf272d reproduces this with a 4 x 3 UInt8 image. A successful write must produce a readable image with the correct pixels. If the format cannot preserve the requested origin, the behavior must be explicit and must not silently change the coordinate.

The shipped Scientific Volume Interoperability bookmark also reports success but writes two TIFF slices without an image directory. Both before and after the histogram changes, the files contain the pixel payload but cannot be opened. This problem predates the histogram batch. The recorded bookmark comparison did not capture a runtime libtiff error string; the cause below combines the reproduced symptom with source inspection.

Steps to Reproduce

  1. Create a 4 x 3, single-component UInt8 image with pixels 0 through 11 in row-major order.
  2. Set the image origin to (-1, 2, 0) and spacing to (0.5, 0.75, 1).
  3. Write it as a TIFF with TiffImageIO::writePixelData.
  4. Check the return value, then reopen the output with a TIFF reader.

Actual: the write returns success, but libtiff cannot open the output. The previously recorded bookmark files have a zero first image-directory offset. A positive X origin is a passing control. The matching end-to-end bookmark uses a 4 x 3 x 2 UInt8 image with origin (-1, 2, 3.5) and XY TIFF output.

Cause

The TIFF writer sets XPOSITION and YPOSITION from the origin. In the tested libtiff, these position tags use unsigned rationals; a negative position cannot be serialized when the image directory is finalized. The writer returns success after scanline writes, while its RAII owner closes the TIFF without a checked finalization result. Source inspection supports this mechanism; the swallowed libtiff diagnostic was not separately captured in the reproduced run.

Verification Unit Test

Add this test to test/TiffImageIOTest.cpp, which already provides TemporaryTiffFile, TiffHandle, and the required includes. It permits an explicit error for a negative origin because the metadata policy is not yet selected; otherwise it requires independently readable dimensions and exact pixels. The positive-origin control must succeed.

TEST_CASE("TiffImageIO:: successful writes with signed origins produce readable pixels", "[TiffImageIO][TIFFOrigin]")
{
  const float32 originX = GENERATE(1.0F, -1.0F);
  CAPTURE(originX);
  TemporaryTiffFile file("TiffImageIO_signed_origin.tif");
  const std::array<uint8, 12> expected{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
  ImageMetadata metadata;
  metadata.width = 4;
  metadata.height = 3;
  metadata.numComponents = 1;
  metadata.dataType = DataType::uint8;
  metadata.origin = FloatVec3{originX, 2.0F, 0.0F};
  metadata.spacing = FloatVec3{0.5F, 0.75F, 1.0F};

  const auto written = TiffImageIO{}.writePixelData(file.path(), expected, metadata);
  if(written.invalid())
  {
    REQUIRE(originX < 0.0F);
    REQUIRE_FALSE(written.errors().empty());
    return;
  }

  TiffHandle input(TIFFOpen(file.path().string().c_str(), "r"), TIFFClose);
  REQUIRE(input != nullptr);
  uint32 width = 0;
  uint32 height = 0;
  REQUIRE(TIFFGetField(input.get(), TIFFTAG_IMAGEWIDTH, &width) == 1);
  REQUIRE(TIFFGetField(input.get(), TIFFTAG_IMAGELENGTH, &height) == 1);
  REQUIRE(width == 4);
  REQUIRE(height == 3);
  std::array<uint8, 4> row{};
  for(uint32 y = 0; y < height; ++y)
  {
    REQUIRE(TIFFReadScanline(input.get(), row.data(), y) == 1);
    REQUIRE(std::equal(row.begin(), row.end(), expected.begin() + static_cast<usize>(y) * row.size()));
  }
}

Run the single registered test after building simplnx_test:

ctest -C Release -R "^TiffImageIO:: successful writes with signed origins produce readable pixels$" --output-on-failure

Observed on the revision above, with the positive control passing:

FAILED: REQUIRE( input != nullptr )
with message: originX := -1.0f
test cases: 1 | 0 passed | 1 failed
assertions: 12 | 11 passed | 1 failed

Proposed Fix

Choose and document how a negative spatial origin is handled: preserve it in a supported representation, report an explicit metadata limitation, or reject it. Do not silently substitute another coordinate. Check directory finalization and propagate failures before the caller commits the temporary file. A failed export must not replace an existing destination with an incomplete image.

Add negative X, negative Y, and nonnegative controls; check each selected image plane and supported pixel type. Include a forced late finalization failure and verify the filter's per-slice publication behavior. Re-run the existing scientific-volume bookmark and independently open and compare both TIFF slices.

Notes

The failure is mentioned as a baseline blocker in simplnx #1888 and DREAM3DNX #1233. simplnx #1610 discusses other TIFF metadata and diagnostics issues; it does not describe this unreadable-write failure. The test above was built and run against public develop with MSVC and libtiff 4.7.1. It does not establish cross-platform behavior or prove out-of-core storage use.

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.