Page MenuHomePhabricator

GrabItkImageMemory can cause memory flaws
Closed, ResolvedPublic

Description

When called in the following execution chain

(1) CastToItkImage( mitkImage, itkImage )
(2) ChangeImageData( itkImage )
(3) GrabItkImageMemory( itkImage, mitkImage )

the internally performed import of the BufferPointer is not safe as it imports the same data pointer the mitkImage holds already.

Executing the GrabitkImageMemory further can lead to uncorrect reference count and hence an attempt for double memory free().

Event Timeline

User hering has pushed new remote branch:

bug-17613-Unsafe_GrabItkImageMemory

ChangeRequest written, branch pushed. Setting flags [ CoreMod + Release ]

New solution proposal pushed to the remote branch.

As discussed with Sascha, the previous solution with exception throwing was too restrictive and not particularly user friendly. The now proposed solution only performs a pointer check and simply passes the image to the output.

The corresponding test and the ChangeRequest document were adapted.

User hering has pushed new remote branch:

bug-17613-Unsafe_GrabItkImageMemory-Int2015-15

Add dependency to 19327 - the tests are otherwise failing because the ImageGeometry value is not set correctly for the test images.

[e8a6d6]: Merge branch 'bug-17613-Unsafe_GrabItkImageMemory-Int2015-15'

Merged commits:

2015-09-16 17:39:21 Jan Hering [432b24]
Remove QuickFix for the ImageGeometryOn bug (19327)


2015-09-16 16:45:41 Jan Hering [9dc131]
Comment on a QuickFix avoiding T19327 effects


2015-09-16 16:37:18 Jan Hering [7d01c1]
Use CPPUNIT style for mitkImageToItkTest


2015-09-16 16:33:32 Jan Hering [0837e0]
Check for self-assignment

  • if the ItkImageImport and GrabItkImageMemory are chained, the target pointer is equal with the source pointer and no action should be taken (otherwise the pointer is released after the grab resulting into an invalid image)

[19f64e]: Merge branch 'bug-17613-Unsafe_GrabItkImageMemory-Int2015-15'

Merged commits:

2015-09-23 15:06:59 Jan Hering [7ee68e]
COMP Skip pointer check for uninitialized images

  • the read probe will not be instantiated for unitialized ones, the ReadAccessor throws an exception