Page MenuHomePhabricator

Certain dicoms cause a segfault in MITK (GDCM) on loading
Closed, ResolvedPublic

Description

Loading some MR(DWI) dicom cause a segfault in the gdcm lib.

dcmdump gives the following output at the end:

W: DcmItem: Non-standard VR ' ' (14\00) encountered while parsing element (3a00,3100), assuming 2 byte length field
E: DcmElement: Unknown Tag & Data (3a00,3100) larger (3072) than remaining bytes (2819) in file, premature end of stream
W: DcmItem: Dataset not in ascending tag order, at element (3a00,3100)
E: dcmdump: Invalid stream: reading file:

interestinly enough some dicoms with same sqeuence on the same scanner do work.

Event Timeline

GDCM tries to sort a list of NULL objects causing the segfault.

The problem including a possible patch has been reported to the gdcm mailing list.

there seems to be a bug in the gdcmSorter.cxx file in Sorter::StableSort .
When a list of filenames (filenames) is parsed it tries to read all the files and if it fails it assigns a NULL to the filelist. (lines 80-95) After this the filelist is sorted using a sort functor, which tries to access the GetDataSet() function of the objects stored in filelist (line 84)

class SortFunctor
...
return (SortFunc)(file1->GetDataSet(), file2->GetDataSet()); )

which causes a segmentation fault for NULL entries.

Possible patch would be to return false if a file could not be read, So this event can be handled by the calling function.

Replacing:

if( reader.Read() )
{
  f = new FileWithName( reader.GetFile() );
  f->filename = *it;
}

else
  {
  f = NULL;
  }

With:

else
{
  std::cerr << "Err: File could not be read: " << it->c_str() << std::endl;
  return false;
}

New remote branch pushed: bug-15800-PatchGDCMSortFunction

Core Change Request:
http://mitk.org/ChangeRequests/15800

Testing data will be uploaded to DATA repo soon.

[42f2f0]: Merge branch 'bug-15800-PatchGDCMSortFunction'

Merged commits:

2013-08-14 16:47:39 Christian Weber [dae7f0]
Added Test case which opens a broken series and checks if it crashes.


2013-08-14 15:37:54 Christian Weber [52e286]
Check for failed sorting in DicomSeriesReader and DiffusionDicomReader


2013-08-14 15:36:47 Christian Weber [a3a1d8]
REGEX REPLACE -> std REPLACE


2013-08-14 15:02:29 Christian Weber [9b1dc7]
Patch for GDCM with crashed when one dicom file cannot be parsed properly