InsightSoftwareConsortium / InsightSoftwareConsortium/ITK
NiftiImageIO: streamed region read of a multi-component image corrupts the heap and aborts
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 748
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 64
Description
Reading a region of a multi-component NIfTI image through streamed extraction corrupts the heap and aborts the process, so there is no exception to catch.
Reproducer (SimpleITK 2.5.5 spelling, but the crash is in the ITK NIfTI IO; Linux x86-64, Python 3.13):
```python
import SimpleITK as sitk
import numpy as np
field = sitk.GetImageFromArray(np.zeros((16, 16, 16, 3), np.float32), isVector=True)
sitk.WriteImage(field, "field.nii")
reader = sitk.ImageFileReader()
reader.SetFileName("field.nii")
reader.ReadImageInformation()
reader.SetExtractIndex([0, 0, 4])
reader.SetExtractSize([16, 16, 4])
reader.Execute()
```
Output:
```
free(): invalid size
Aborted (signal 6)
```
The same extraction on a scalar `.nii` works, and reading the vector image whole works, so it is specifically the region path of a multi-component image. My guess is a buffer sized on the scalar voxel count while the IO copies component-interleaved data, but I have not traced it.
Why it matters to us: we stream large medical volumes region by region (deep-learning pipelines where a displacement field stored as vector NIfTI is read in slabs), and a process abort cannot be guarded against at the Python level. We currently detect this case from the header and force a whole-volume read for vector NIfTI, which defeats the streaming for that format.
Contributor guide
Research direction
Start with the ITK NIfTI IO region-read path and run the supplied Python ImageFileReader reproducer on the multi-component and scalar cases. Trace the streamed extraction buffer sizing and component-interleaved copy, then verify that vector NIfTI slab reads complete without heap corruption or process abort while whole-image and scalar reads remain working.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100