dcmjs-org / dcmjs

Javascript implementation of DICOM manipulation
https://dcmjs.netlify.com/
MIT License
291 stars 110 forks source link

Reading malformed DICOM file causes infinite loop #326

Closed richard-viney closed 1 year ago

richard-viney commented 1 year ago

Loading the following malformed DICOM file results in an infinite loop in the dcmjs parser:

https://drive.google.com/file/d/1LySSmhpfNPLHAYR9WObIHL_NlpkX9a-i/view?usp=sharing

This happens because the meta length is assumed to be present and correctly formed, but in this DICOM file it is absent. Interestingly, pydicom loads the file without any errors. I haven't investigated exactly how/why it is achieving this.

pieper commented 1 year ago

Thanks for reporting and providing the data. You are right, this is a very minimal and malformed dataset, not even any pixel data. Still, avoiding an infinite loop would be nice, and loading if we can I guess. Can you create a PR?

bash-3.2$ dcmdump /tmp/untitled\ folder/infinite-loop.dcm 
W: DcmMetaInfo: No Group Length available in Meta Information Header

# Dicom-File-Format

# Dicom-Meta-Information-Header
# Used TransferSyntax: Little Endian Explicit
(0002,0002) UI =UltrasoundImageStorage                  #  28, 1 MediaStorageSOPClassUID
(0002,0003) UI [1.2.3]                                  #   6, 1 MediaStorageSOPInstanceUID
(0002,0010) UI =LittleEndianExplicit                    #  20, 1 TransferSyntaxUID
(0002,0012) UI [1.2.3.4]                                #   8, 1 ImplementationClassUID

# Dicom-Data-Set
# Used TransferSyntax: Little Endian Explicit
(0008,0016) UI =UltrasoundImageStorage                  #  28, 1 SOPClassUID
(0008,0018) UI [1.1]                                    #   4, 1 SOPInstanceUID
(0008,0020) DA [20210125]                               #   8, 1 StudyDate
(0008,0030) TM [125808]                                 #   6, 1 StudyTime
(0008,0060) CS [US]                                     #   2, 1 Modality
(0020,000d) UI [1]                                      #   2, 1 StudyInstanceUID
(0020,000e) UI [1.1.1]                                  #   6, 1 SeriesInstanceUID
conrad-scherb commented 1 year ago

I've put up a PR now that causes a throw and reading to be abandoned if no meta length tag is present along with a test.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 0.29.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: