Page MenuHomePhabricator

SegFault when activating MitkIGTTrackingToolbox plugin while having registered a custom stl reader
Closed, ResolvedPublic

Description

We have registered a custom STL reader that converts an stl file in a different data format than mitk::Surface.

The MitkIGTTrackingToolbox plugin expects though that when a stl file that is kept as a ressource will be read into an mitk::Surface format. In mitkTrackingVolumeGenerator line 92ff a dynamic_cast onto mitk::Surface is used but then the result is not checked against nullptr.

This leads to a seg fault when accessing <cast_result>->GetVtkPolyData().

Solution is a quick check on nullptr and in case of a non surface object delivering an empty new VtkPolyData with an appropriate error message.

Code snippet modified with solution:
*begin snippet*

// from here on, we assume that filename contains an actual filename and not a magic string

us::Module* module = us::GetModuleContext()->GetModule();

us::ModuleResource moduleResource = module->GetResource(filename);

std::vector<mitk::BaseData::Pointer> data = mitk::IOUtil::Load(moduleResource);

 if(data.empty())
   MITK_ERROR << "Exception while reading file: " << moduleResource.GetResourcePath();

 mitk::Surface::Pointer fileoutput = dynamic_cast<mitk::Surface*>(data[0].GetPointer());

 if (fileoutput == nullptr)
 {
     MITK_ERROR << "Exception while casting data loaded from file: " << moduleResource.GetResourcePath();
     output->SetVtkPolyData(vtkSmartPointer<vtkPolyData>(vtkPolyData::New()));
 } 
 else
 {
     output->SetVtkPolyData(fileoutput->GetVtkPolyData());
 }

*end snippet*

I still need to clarify how I can adjust our proprietary stl reader to not read that ressource but to let the mitkSurfaceStlIO class read it. This is a bit more difficult as this reader doesn't set its read and write ranking. But I will check.

Set to minor as only a few users probably use a custom stl reader.

Event Timeline

added and signed off pull request iwegner:bug-19825-SegFault_in_IGTTrackingToolbox_pluigin

https://github.com/MITK/MITK/pull/135

;) Ingmar

checked changes and works as it should.
With the changes no crash occurs and the following error messages are displayed in console:

220.99 core.mod.igt.trckVolGen ERROR: Exception while casting data loaded from f
ile: /NDIPolarisSpectra.stl
[32392] ERROR \"ext.mitk\" | Exception while casting data loaded from file: /ND
IPolarisSpectra.stl
229.66 core.mod.igt.trckVolGen: volume: NDIPolarisSpectra.stl
234.95 core.mod.igt.trckVolGen ERROR: Exception while casting data loaded from f
ile: /NDIPolarisSpectra.stl
[32392] ERROR \"ext.mitk\" | Exception while casting data loaded from file: /ND
IPolarisSpectra.stl
235.03 core.mod.igt.trckVolGen: volume: NDIPolarisSpectra.stl
237.44 core.mod.igt.trckVolGen ERROR: Exception while casting data loaded from f
ile: /NDIPolarisSpectra.stl
[32392] ERROR \"ext.mitk\" | Exception while casting data loaded from file: /ND
IPolarisSpectra.stl

;) Ingmar

franza lowered the priority of this task from Low to Wishlist.Feb 27 2017, 9:30 AM

added and signed off pull request iwegner:bug-19825-SegFault_in_IGTTrackingToolbox_pluigin

https://github.com/MITK/MITK/pull/135

I just improved on the original pull request by Ingmar. My pull request is https://github.com/MITK/MITK/pull/184.

Given an alternative and higher ranked STL reader, the different pull requests behave like follows:

  • MITK master: TrackingVolumeGenerator will access a nullptr, crashing most of the time
  • Ingmar's solution 135: TrackingVolumeGenerator will not crash but not produce a tracking volume neither
  • Daniel's solution 184: TrackingVolumeGenerator will not crash and produce the requested tracking volume

The actual problem comes down to the fact that IOUtil proposes a method LoadSurface() but this method would equally fail to load surfaces in the presence of multiple STL MIME types - I'll describe this in an independent bug.