dgobbi / vtk-dicom

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

Element (0029,0010) "Item length exceeds the bytes remaining in file" #223

Closed hkroeger closed 4 months ago

hkroeger commented 11 months ago

I wrote some code using VTK-Dicom to read CT scan data. I actually have two sources: one from a GE scanner and one from a Siemens scanner.

The GE data is read just fine.

When I use the same code to read the data from the Siemens scanner, I get the following errors below.

gdcmdump reads the file in question without errors and the problem seems to be related to the element labelled "(0029,0010) LO [SIEMENS CSA HEADER]".

Is there a known problem with this field? If so, is there any recommended workaround to read such data?

Thanks!

PS: I built the most recent commit b69e7ac992736f4b7e58587c9ad4de110510b302 of vtk-dicom

2023-12-18 09:48:34.057 (   0.345s) [        589FF640]     vtkDICOMParser.cxx:2457   ERR| vtkDICOMParser (0x7efb48003400): At byte offset 3272 in file "../CT-Daten_org/INST1": In Element (0029,0010), in Sequence (0000,0000) [Item 1]: Item length exceeds the bytes remaining in file.
2023-12-18 09:48:34.057 (   0.345s) [        589FF640]     vtkDICOMReader.cxx:2397   ERR| vtkDICOMReader (0x7efb489215c0): ERROR: In /home/hannes/Projekte/build-insight-Desktop_superbuild-Debug/src/addons/insight-bone/vtkdicom-prefix/src/vtkdicom/Source/vtkDICOMParser.cxx, line 2457
vtkDICOMParser (0x7efb48003400): At byte offset 3272 in file "../CT-Daten_org/INST1": In Element (0029,0010), in Sequence (0000,0000) [Item 1]: Item length exceeds the bytes remaining in file.

2023-12-18 09:48:34.057 (   0.345s) [        589FF640]     vtkDICOMParser.cxx:2457   ERR| vtkDICOMParser (0x7efb48003400): At byte offset 3404 in file "../CT-Daten_org/INST1": In Element (0000,0000): Item length exceeds the bytes remaining in file.
2023-12-18 09:48:34.057 (   0.345s) [        589FF640]     vtkDICOMReader.cxx:2397   ERR| vtkDICOMReader (0x7efb489215c0): ERROR: In /home/hannes/Projekte/build-insight-Desktop_superbuild-Debug/src/addons/insight-bone/vtkdicom-prefix/src/vtkdicom/Source/vtkDICOMParser.cxx, line 2457
vtkDICOMParser (0x7efb48003400): At byte offset 3404 in file "../CT-Daten_org/INST1": In Element (0000,0000): Item length exceeds the bytes remaining in file.
hkroeger commented 11 months ago

Update: I can read the DICOM files, if I convert them all using gdcmconv --remove-gl The command line help says: --remove-gl Remove group length (deprecated in DICOM 2008).

dgobbi commented 11 months ago

Thanks for the report. There's nothing special about "(0029,0010) LO [SIEMENS CSA HEADER]", it just starts an important Siemens private group in the file. The part of the error that worries me is "in Sequence (0000,0000)", since no valid tag ever has the value (0000,0000).

Can you do a gdcmdump of the original file and send me the dump? I want to see where the group length elements and sequence elements are. Also, of course, be sure to XX out any sensitive information in the dump.

hkroeger commented 11 months ago

Thanks for the feedback! No problem. Please find the first file of the series attached: INST1.zip

dgobbi commented 11 months ago

I found the problem in vtkDICOMParser.cxx and pushed a commit that should fix it (6a81888). Please try updating from the master branch and let me know if it works for you.

There was a bug with parsing files with an explicit VR transfer syntax that contained a sequence of defined length that had VR=UN. Here, the difficulty was the "ApplicationHeaderSequence". The bug caused an error to be thrown at the first element of the sequence, not because there was anything wrong with that element, but only because it was the first element in a sequence that was incorrectly parsed.

(0029,1140) UN (actually SQ) "ApplicationHeaderSequence"
  (0029,0010) LO "PrivateCreator" : [SIEMENS MEDCOM HEADER]

I'm re-attaching the DICOM file after XX-ing a few attributes and zeroing the image: INST1.zip

hkroeger commented 11 months ago

Dear David, thanks a lot for the prompt fix! I will try and let you know. Regarding the scan data: it is the scan of a specimen for research. There is no real patient data in it.