Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot load DICOM instance where SQ is using VR:UN with undefined length #141

Open
malaterre opened this issue Mar 30, 2020 · 9 comments
Open

Comments

@malaterre
Copy link
Contributor

For some reason I can load a CT Image when all sequences are using defined length (VR:UN) but I cannot load the same instance when the sequences are using undefined length (VR:UN).

  • CT-SQ-UN-IVRLE-undeflen.dcm: not OK
  • CT-SQ-UN-IVRLE-deflen.dcm: OK

CT-SQ-UN-IVRLE.zip

Reference:

@malaterre malaterre changed the title Cannot load DICOM instance where SQ is using Vr:UN with undefined length Cannot load DICOM instance where SQ is using VR:UN with undefined length Mar 30, 2020
@malaterre
Copy link
Contributor Author

Someone may want to move this issue in the other project "dicomParser"

@dannyrb dannyrb transferred this issue from cornerstonejs/cornerstoneWADOImageLoader Mar 31, 2020
@dannyrb
Copy link
Member

dannyrb commented Mar 31, 2020

@malaterre, transferred. Thanks for the report. This feels similar to a report we had for "private fields" where we did not know the length, but I could be mistaken.

@yagni
Copy link
Collaborator

yagni commented Aug 10, 2020

@malaterre Are you referencing the unpkg build by any chance? I think it might be corrupted or out of date. If I use the dump with data dictionary example, dropping your undeflen file on it works just fine unless I switch to using the unpkg build, at which point I get a buffer overrun.

@yagni
Copy link
Collaborator

yagni commented Oct 1, 2021

@malaterre Can you confirm whether this is still an issue? I can successfully drop both of the above files into the dump with data dictionary example. Is there some other way the undefined length file is failing to load?

@malaterre
Copy link
Contributor Author

@yagni Can you post the dump somewhere please ?

@yagni
Copy link
Collaborator

yagni commented Oct 1, 2021

@malaterre After trying again, I noticed both don't throw any errors during dumpWithDataDictionary, but the file with defined sequence lengths doesn't parse the sequences. Instead, they're treated as binary, as shown below:
image

The corresponding sequences in the file with undefined lengths:
image

Aside from the sequence differences, the rest of the files dump the same. Is this what you were referring to? If so, I think that's correct behavior: note 5 in section 6.2.2 of the standard says you can parse a UN element as if it were a SQ, but only if it has undefined length.

Here's the undeflen dump and here's the deflen dump

@malaterre
Copy link
Contributor Author

@yagni In this case you should specify (somewhere in the documentation) that dicomParser will never convert CP-246 encoded SQ into SQ (so one can never access the contained Data Element). I find the behavior quite surprising since this would prevent the library from reading any needed nested dataelement from a know SQ attribute.

@yagni
Copy link
Collaborator

yagni commented Oct 22, 2021

@malaterre I'd like to make a PR for this, so please bear with me while I understand what the desired behavior is here. The difficulty here is dicomParser doesn't know an attribute is SQ if the VR isn't explicit (or if it's explicit and marked UN) since we don't have a data dictionary unless the user provides a VR callback. If a UN element has undefined length, we know it's SQ because SQ is the only element (other than an item, and that has a specific tag) that can have an undefined length. However, if it has a defined length, it can either be a sequence or some other kind of element.

Given that, would this satisfy a standards-compliant behavior for a UN element:

  1. If undefined length or VRCallback returns SQ, parse as implicit VR little endian sequence
  2. Otherwise, treat as a single element.

If I'm missing something or there's a better way, please let me know.

P.S. Thanks for all your hard work on GDCM--what a contribution to the field!

@malaterre
Copy link
Contributor Author

@yagni Thanks for your kind words.

Reading Implicit Transfer Syntax without a data dictionary is identical to the behavior you describe above. So I suspect the right fix is implement "UN + defined Length + Explicit Transfer Syntax", just as any "SQ element in Implicit Transfer Syntax". Sorry I do not know the codebase. You need to convert "on-the-fly" your binary data to SQ when given a dictionary (just as in the case of implicit).

Let me know if the above make sense.

Re-reading this thread (see @dannyrb message) I also vaguely recall a hack about private attributes. So I suspect the implementation is already ready for UN + defined length + private attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants