Skip to content

Commit a0cf385

Browse files
lassoanhjmjohnson
authored andcommitted
BUG: Fix image file reader crash when axis direction vector is short
The image file reader crashed when an IO class stored additional non-spatial (such as time) dimension in the image array and provided axis direction vectors that covered only the spatial axes. The previous implementation crashed (due to vector out of bounds access), while the current implementation augments the direction matrix with unit direction vectors for additional axes.
1 parent d0b0706 commit a0cf385

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Modules/IO/ImageBase/include/itkImageFileReader.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>::GenerateOutputInformation()
182182
axis = directionIO[i];
183183
for (unsigned int j = 0; j < TOutputImage::ImageDimension; ++j)
184184
{
185-
if (j < numberOfDimensionsIO)
185+
if (j < numberOfDimensionsIO && j < axis.size())
186186
{
187187
direction[j][i] = axis[j];
188188
}
189189
else
190190
{
191-
direction[j][i] = 0.0;
191+
direction[j][i] = (i == j ? 1.0 : 0.0);
192192
}
193193
}
194194
}

0 commit comments

Comments
 (0)