InsightSoftwareConsortium / InsightSoftwareConsortium/ITK

Problems with NRRD IO writing ".nhdr"

Open
#6,820 0 comments 0 reactions 0 assignees View on GitHub
type:Bug
Dominant language
C++
Stars
1.7k
Forks
748
Avg merge
1d 1h
Merged PRs (30d)
64

Description

Observed with ITK 5.4.5. Haven't tried 5.4.7.

Using itk::ImageFileWriter with filename ".nhdr" (no stem, just the extension), when it writes, it selects NRRD IO and writes the following to standard error:
```
[...] /tmp/guix-build-insight-toolkit-5.4.5.drv-0/source/Modules/IO/NRRD/src/itkNrrdImageIO.cxx:1145:
ITK ERROR: NrrdImageIO(0x514000000240): Write: Error writing .nhdr:
[nrrd] nrrdSave:
[nrrd] nrrdWrite: trouble
[nrrd] _nrrdWrite:
[nrrd] _nrrdFormatNRRD_write: can't create data file name: nio's path and base empty
```
but it still writes an empty file with that name.
Also leaks memory:

```
==2760==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 149 byte(s) in 1 object(s) allocated from:
#0 0x7fbabf0f9610 in calloc (/gnu/store/7iwcvd0gjrfq6bj7zvf3r59baw6vib5a-gcc-14.3.0-lib/lib/libasan.so.8+0xf9610)
#1 0x7fbabe1739a4 in itk_biffGet (/gnu/store/gvrihm8jyq9mn8a3jm0jyn641ivd3dxw-insight-toolkit-5.4.5/lib/libITKNrrdIO-5.4.so.1+0x129a4)

Indirect leak of 2792 byte(s) in 1 object(s) allocated from:
#0 0x7fbabf0f9610 in calloc (/gnu/store/7iwcvd0gjrfq6bj7zvf3r59baw6vib5a-gcc-14.3.0-lib/lib/libasan.so.8+0xf9610)
#1 0x7fbabe175c52 in itk_nrrdNew (/gnu/store/gvrihm8jyq9mn8a3jm0jyn641ivd3dxw-insight-toolkit-5.4.5/lib/libITKNrrdIO-5.4.so.1+0x14c52)
#2 0x420250 in itk::ImageFileWriter >::Write() (/path/to/project/build/test/src/test+0x420250)
#3 0x417b41 in itk::ImageFileWriter >::Update() (/path/to/project/build/test/src/test+0x417b41)
#4 0x40ca04 in (anonymous namespace)::MyTest(std::basic_string_view >, bool, bool) (/path/to/project/build/test/src/test+0x40ca04)
#5 0x40e297 in OutputFilenamesTest_Nrrd_Test::TestBody() (/path/to/project/build/test/src/test+0x40e297)
#6 0x7fbabebfa1ae in void testing::internal::HandleExceptionsInMethodIfSupported(testing::Test*, void (testing::Test::*)(), char const*) (whatever/lib/libgtest.so.1.17.0+0x5e1ae)

Indirect leak of 344 byte(s) in 1 object(s) allocated from:
#0 0x7fbabf0f9610 in calloc (/gnu/store/7iwcvd0gjrfq6bj7zvf3r59baw6vib5a-gcc-14.3.0-lib/lib/libasan.so.8+0xf9610)
#1 0x7fbabe17548f in itk_nrrdIoStateNew (/gnu/store/gvrihm8jyq9mn8a3jm0jyn641ivd3dxw-insight-toolkit-5.4.5/lib/libITKNrrdIO-5.4.so.1+0x1448f)
#2 0x420250 in itk::ImageFileWriter >::Write() (/path/to/project/build/test/src/test+0x420250)
#3 0x417b41 in itk::ImageFileWriter >::Update() (/path/to/project/build/test/src/test+0x417b41)
#4 0x40ca04 in (anonymous namespace)::MyTest(std::basic_string_view >, bool, bool) (/path/to/project/build/test/src/test+0x40ca04)
#5 0x40e297 in OutputFilenamesTest_Nrrd_Test::TestBody() (/path/to/project/build/test/src/test+0x40e297)
#6 0x7fbabebfa1ae in void testing::internal::HandleExceptionsInMethodIfSupported(testing::Test*, void (testing::Test::*)(), char const*) (whatever/lib/libgtest.so.1.17.0+0x5e1ae)

Indirect leak of 264 byte(s) in 3 object(s) allocated from:
#0 0x7fbabf0f9610 in calloc (/gnu/store/7iwcvd0gjrfq6bj7zvf3r59baw6vib5a-gcc-14.3.0-lib/lib/libasan.so.8+0xf9610)
#1 0x7fbabe170d91 in itk_airArrayNew (/gnu/store/gvrihm8jyq9mn8a3jm0jyn641ivd3dxw-insight-toolkit-5.4.5/lib/libITKNrrdIO-5.4.so.1+0xfd91)

Indirect leak of 8 byte(s) in 2 object(s) allocated from:
#0 0x7fbabf0f9c57 in malloc (/gnu/store/7iwcvd0gjrfq6bj7zvf3r59baw6vib5a-gcc-14.3.0-lib/lib/libasan.so.8+0xf9c57)
#1 0x7fbabe1720a0 in itk_airStrdup (/gnu/store/gvrihm8jyq9mn8a3jm0jyn641ivd3dxw-insight-toolkit-5.4.5/lib/libITKNrrdIO-5.4.so.1+0x110a0)

SUMMARY: AddressSanitizer: 3557 byte(s) leaked in 8 allocation(s).
```

It shouldn't write an empty file and it shouldn't leak memory.

Contributor guide

Open the contributing guide

Research direction

Start in Modules/IO/NRRD/src/itkNrrdImageIO.cxx and reproduce the .nhdr case from the issue, then inspect the OutputFilenamesTest_Nrrd_Test path shown in the stack trace. Done means writing .nhdr reports failure without leaving an empty file and the test run no longer reports the shown NRRD-related leaks.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-vision
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.