InsightSoftwareConsortium / ITK

Insight Toolkit (ITK) -- Official Repository. ITK builds on a proven, spatially-oriented architecture for processing, segmentation, and registration of scientific images in two, three, or more dimensions.
https://itk.org
Apache License 2.0
1.41k stars 663 forks source link

Fix 32bits dicom read crash #4522

Closed lassoan closed 6 months ago

lassoan commented 6 months ago

Fix crash in ITK DICOM reader when attempting to read an unusual but valid DICOM file, which has 32 bits allocated. Fixes the error reported at https://discourse.slicer.org/t/slicer-crashes-while-trying-to-load-dicom-files/34931/3

PR Checklist

Refer to the ITK Software Guide for further development details if necessary.

lassoan commented 6 months ago
  • split the GDCM change into a patch and PR against malaterre/GDCM for the release branch

malaterre/GDCM: I got a message when I committed that I would need to send something to sourceforge. The link did not work, so I hoped that I didn't need to deal with it. It seems that GDCM is on github now - https://github.com/malaterre/GDCM - do you mean I should send a pull request there?

  • Add a test here with the file reported on the Slicer Discourse for both ITKIOGDCM and ITKIODCMTK to ensure we do not crash

I've asked for permission for using a slice of the data set as test data: https://discourse.slicer.org/t/slicer-crashes-while-trying-to-load-dicom-files/34931/5

thewtex commented 6 months ago

https://github.com/malaterre/GDCM - do you mean I should send a pull request there?

Yes, please. We integrate patches from there into ITK if accepted.

I've asked for permission for using a slice of the data set as test data: https://discourse.slicer.org/t/slicer-crashes-while-trying-to-load-dicom-files/34931/5

Most excellent.

lassoan commented 6 months ago

Submitted a PR to GDCM:

https://github.com/malaterre/GDCM/pull/168

thewtex commented 6 months ago

Thank you @lassoan !

LGTM.

Path to integration:

  1. Merge #4521
  2. I will create another PR that integrates malaterre/GDCM#168 via our subtree merge process.
  3. Rebase this PR
lassoan commented 6 months ago

Thank you! Let me know if you need any help from me.

lassoan commented 6 months ago

The GDCM pull request has been merged.

hjmjohnson commented 6 months ago

@lassoan Thanks!

thewtex commented 6 months ago

Both the GDCM patch for this branch and the GDCM patch for #4521 have been integrated into GDCM, and these are integrated in #4521 -> after #4521 has been merged, this branch can be rebased and merged.

thewtex commented 6 months ago

Dropped the GDCM patch (integrated via malaterre/GDCM#168 and #4521 ) and rebased.

lassoan commented 6 months ago

Thank you @thewtex!

dzenanz commented 6 months ago

From the dashboard:

/Users/builder/external/ITK/Modules/IO/GDCM/src/itkGDCMImageIO.cxx:191:3: error: invalid use of 'this' outside of a non-static member function
  itkDebugMacro(<< "No DICOM magic number found, but the file appears to be DICOM without a preamble.");
  ^

Probably use itkWarningMacro instead of itkDebugMacro?

SimonRit commented 6 months ago

It believe it will be the same problem for itkWarningMacro (use of this->GetNameOfClass()). I was about to submit the following patch:

-  itkDebugMacro(<< "No DICOM magic number found, but the file appears to be DICOM without a preamble.");
+#ifndef NDEBUG
+  itkGenericOutputMacro("No DICOM magic number found, but the file appears to be DICOM without a preamble.");
+#endif

which compiles, what do you think?

dzenanz commented 6 months ago

I would prefer to remove the debug statement entirely.

SimonRit commented 6 months ago

Sounds good to me, that should also compile!

lassoan commented 6 months ago

Sorry, all testing was done in release mode, probably that's why this error was not caught.

The log message was there before, I just switched to using a macro. Since detection of a DICOM file without a preamble requires some heuristics, so when investigating why a file is detected/not detected as DICOM it might be useful to know the result of the heuristic check. But it should not be logged every time when a DICOM file without a preamble is encountered.

Has somebody started to work on a new pull request or I should do it?

dzenanz commented 6 months ago

I have not started any work. I am giving other people a chance to fix this 😄

SimonRit commented 6 months ago

Nope, I haven't done more than testing the patch I suggested. Go ahead!

seanm commented 6 months ago

@lassoan do you have a fix in the works?

dzenanz commented 6 months ago

@seanm There is #4544.