dgobbi / vtk-dicom

A set of classes for using DICOM in VTK.
BSD 3-Clause "New" or "Revised" License
259 stars 94 forks source link

Heap corruption with YBR_FULL NEMA test images #234

Closed RobertHabrich closed 1 month ago

RobertHabrich commented 1 month ago

Using this simple test application, I can consistently reproduce a heap corruption when using a debug version of vtk-dicom 0.8.16 when left-clicking into the render window (to unload the first image and load another one):

#include <vtkInteractorStyleImage.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkDICOMReader.h>
#include <vtkImageViewer2.h>
#include <vtkCallbackCommand.h>

vtkSmartPointer<vtkDICOMReader> reader;

void callbackFunc(vtkObject*, long unsigned int, void* , void*)
{
    reader->SetFileName(R"(PATH_TO_FMAG0035)");
    reader->Update();
}

int main(int, char*[])
{
    reader = vtkSmartPointer<vtkDICOMReader>::New();
    reader->SetFileName(R"(PATH_TO_FMAG0001)");
    reader->Update();

    auto iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    auto style = vtkSmartPointer<vtkInteractorStyleImage>::New();
    iren->SetInteractorStyle(style);

    vtkNew<vtkCallbackCommand> clickCallback;
    clickCallback->SetCallback(callbackFunc);
    iren->AddObserver(vtkCommand::LeftButtonPressEvent, clickCallback);

    vtkNew<vtkImageViewer2> imageViewer;
    imageViewer->SetInputConnection(reader->GetOutputPort());
    imageViewer->SetupInteractor(iren);
    imageViewer->Render();
    imageViewer->GetRenderWindow()->SetSize(800, 800);
    imageViewer->GetRenderer()->ResetCamera();
    imageViewer->Render();
    iren->Start();
    return 0;
}

This is the heap corruption message I get:

image

These are the two sample images I'm using:

YBR_FULL_HEAP_CORRUPTION_SAMPLES.zip

dgobbi commented 1 month ago

Thanks for the report. I've tested your files on my linux box with valgrind, and I likewise see heap corruption,

==11483== Invalid write of size 1
==11483==    at 0x4A0D874: vtkDICOMReader::YBRToRGB(int, int, void*, long long)
dgobbi commented 1 month ago

Fixed by 4ea84f1.

RobertHabrich commented 1 month ago

That was a very fast fix 👍 Have also verified that it is working properly in our environment. Thank you