BUG: Reject or safely write TIFFs with negative origins

Aperta
#1,914 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 6 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C++
Stelle
18
Fork
15
Merge medio
4g 23h
PR unite (30g)
42

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di BlueQuartzSoftware/simplnx

Tutte le issue di BlueQuartzSoftware/simplnx

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.