Fix 32bits dicom read crash#4522
Conversation
| static bool | ||
| readPreambleDicom(std::ifstream & file) | ||
| bool | ||
| isPreambleDicom(std::ifstream & file) | ||
| { | ||
| file.seekg(0, std::ios::beg); | ||
| std::vector<char> buffer(DCM_PreambleLen + DCM_MagicLen); | ||
| file.read(&buffer[0], buffer.size()); | ||
| if (!file) | ||
| { | ||
| return false; | ||
| } | ||
| const char * magicReadFromFile = &buffer[DCM_PreambleLen]; | ||
| return strncmp(magicReadFromFile, DCM_Magic, DCM_MagicLen) == 0; | ||
| } |
There was a problem hiding this comment.
- Thanks @lassoan Just wondering, how does your pull request relate to BUG: DCMTK reader wrongly rejects file with preamble #4501 ? Didn't pull request 4501 fix the problem already?
More in detail, isPreambleDicom is just a style improvement to readPreambleDicom, right?
There was a problem hiding this comment.
Yes, my first commit is just a style improvement (and a little performance improvement) over #4501. There is no functional difference.
#4501 did not fix the issue because the application first tries to read the DICOM image using GDCM and if it fails then it uses DCMTK. However, GDCM did not return with an error but it crashed the application, so the application did not have a chance to use DCMTK.
thewtex
left a comment
There was a problem hiding this comment.
Very nice @lassoan !
Could you please:
- split the GDCM change into a patch and PR against
malaterre/GDCMfor thereleasebranch - Add a test here with the file reported on the Slicer Discourse for both ITKIOGDCM and ITKIODCMTK to ensure we do not crash
?
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?
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 |
Yes, please. We integrate patches from there into ITK if accepted.
Most excellent. |
|
Submitted a PR to GDCM: |
e3058e6 to
55f2f0c
Compare
|
Thank you @lassoan ! LGTM. Path to integration:
|
|
Thank you! Let me know if you need any help from me. |
|
The GDCM pull request has been merged. |
|
@lassoan Thanks! |
Do not test for no-preamble DICOM file format if standard preamble format is found. Use DCMTK constants (instead of hardcoding the preamble size, magic word, etc.). Remove unnecessary "static" keyword from function in anonymous namespace. Simplified debug message of a DICOM file without preamble.
GDCM used to crash the application when it encountered a DICOM image that had 32 bits stored. This new test checks that GDCM does not crash anymore for such images.
55f2f0c to
7e350ef
Compare
|
Dropped the GDCM patch (integrated via malaterre/GDCM#168 and #4521 ) and rebased. |
|
Thank you @thewtex! |
|
From the dashboard: Probably use |
|
It believe it will be the same problem for itkWarningMacro (use of this->GetNameOfClass()). I was about to submit the following patch: which compiles, what do you think? |
|
I would prefer to remove the debug statement entirely. |
|
Sounds good to me, that should also compile! |
|
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? |
|
I have not started any work. I am giving other people a chance to fix this 😄 |
|
Nope, I haven't done more than testing the patch I suggested. Go ahead! |
|
@lassoan do you have a fix in the works? |
…bits-dicom-read-crash Fix 32bits dicom read crash
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.