BUG: Reject or safely write TIFFs with negative origins
维护者通常 6 天内回复
还没有人认领这个 Issue。
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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
- Create a 4 x 3, single-component UInt8 image with pixels
0through11in row-major order. - Set the image origin to
(-1, 2, 0)and spacing to(0.5, 0.75, 1). - Write it as a TIFF with
TiffImageIO::writePixelData. - 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.
- 主要语言
- 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 天内回复