Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T22211: Potential crash in statistics calculator #171

Closed

Conversation

KuznetsovAlexander
Copy link
Contributor

Problem is in smart pointers in calculator's members and in thrown exception.

Calculator contains two smart pointers to images: m_Image and m_InternalImage that is actually points to some slice from m_Image.
m_InternalImage is initialized in ImageStatisticsCalculator::ComputeStatistics() (inside ExtractImageAndMask()) and is cleared at the end of this function.
But if there is an exception in ExtractImageAndMask() (for example, if we calculate statistics for planar figure that is outside of image's boundaries), m_InternalImage isn't cleared at the end and still points to some slice. So far so good.

Later, when you set up new image to calculator, old image from m_Image is deleted but its ImageData isn't because m_InternalImage data holds it as parent. And of course m_InternalImage still exists at this point.
Later, ExtractImageAndMask() is called, m_InternalImage is rewritten, old image from it is deleted, image data from old m_Image is also deleted and deletes its own ImageVtkWriteAccessor. Which tries to access old m_Image that was deleted some time ago. And there is a crash.

In this PR I've moved m_InternalImage from member to local variable, so it will be released even in case of exception.

Signed-off-by: KuznetsovAlexander KuznetsovAlexander@rambler.ru

…xceptions.

AUT-1279
Signed-off-by: KuznetsovAlexander <KuznetsovAlexander@rambler.ru>
@kislinsk
Copy link
Contributor

Thank you for the contribution. However, we have completely rewritten the image statistics backend, which will be merged in the next days. We'll have a look if there's a similar bug in the new backend, though.

@kislinsk kislinsk closed this Nov 30, 2016
@KuznetsovAlexander KuznetsovAlexander deleted the stat-calculator-crash-mitk branch December 5, 2016 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants