Page MenuHomePhabricator

Crash in mitk::Image::GetPixelValueByWorldCoordinate(..)
Closed, ResolvedPublic

Description

Calling mitk::Image::GetPixelValueByWorldCoordinate() with a world position that translates to a negative pixel index causes invalid memory access.

The if statement around lines 186 seems to be modified in order to fix warnings. However, the logic was necessary, because itk::Index CAN have negative indices. I am not 100% sure about the meaning of the 2D case that is checked, but the 3D case will almost always lead to a crash when the resulting index is negative.

When this is fixed, a simple test case should be added to mitkImageText.cpp

Jan, I'm assigning this to you because git told me that you were the one who last touched that piece of code. However I can be of assistance, e.g. with constructing the test case.

This fix should make it into the snapshot release.

Event Timeline

I have removed the "itkIndex[i] > 0" check because of my assumption, that the index is actually an unsigned type. The fix is simple and clear, as open question remains the handling of such case.

(1) simplest - as it was before, just make a MITK_WARN output informing about an access with negative index

(2) exception

(3) something else? ( returning NaN, ...)

The (1) does not change the behaviour of the method, it simply returns the default value which is set to 0.0. For testing this lefts only one option, i.e.

MITK_TEST_CONDITION_REQUIRED( image->GetPixelValueByWorldCoordinate(position, timestep) == 0, "Test access to the outside of the image")

with position manually shifted outside of the volume. But since also a 0.0 is a usual image value, the significant part for the negative index access is the warning put to the console which cannot be tested.

The old behaviour of the GetPixelValue* methods was returning 0 on invalid index position, so the bugfix will implement the solution (1) [see previous comment]

MITK-1-0 keyword is obsolete, we use Target Milestones in the future.

[e4380e]: Merge branch 'bug-11978-Crash-on-negative-index-access'

Merged commits:

2012-06-06 10:34:28 Jan Hering [91c1de]
Negative index value checking in mitkImageTest


2012-06-06 10:33:24 Jan Hering [19e69a]
Code simplification

  • let GetPixelValueByWorldCoordinates call the GetPixelValueByIndex on
  • the transformed position

2012-06-06 10:32:12 Jan Hering [b35877]
Added negative index value checking

  • to avoid out-of-range access to the image memory

Continuous dartclients green. Issue fixed. Closing bug.