Skip to content

Fix spurious SequenceDelimitationItem in DICOMDecompressor output#40

Open
jmesterh wants to merge 1 commit intojohnperry:masterfrom
jmesterh:encapsulated-decompression-fix
Open

Fix spurious SequenceDelimitationItem in DICOMDecompressor output#40
jmesterh wants to merge 1 commit intojohnperry:masterfrom
jmesterh:encapsulated-decompression-fix

Conversation

@jmesterh
Copy link

@jmesterh jmesterh commented Mar 9, 2026

as noted at https://groups.google.com/g/rsnas-ctpmirc-user-group/c/DtQ8vzkBzCw

Problem

For encapsulated transfer syntaxes like JPEG 2000 DICOMDecompressor.decompress() writes a spurious SequenceDelimitationItem (fffe,e0dd) after pixel data when pixel data is the last element, creating an invalid DICOM file.

Root Cause

Commit 2ae3e71 commented out the fileLength guard in the post-pixel-data loop across five files. That was fine in the other four since their loop structures naturally advance past stale tags. But DICOMDecompressor is different, after skipping encapsulated pixel data fragments, the parser's last-read tag is still the SeqDelimitationItem. When pixel data is the last element, hasSeenEOF() is false and getReadTag() returns that stale tag (not -1), so the loop writes it to the output.

Fix

I restructured the post-pixel-data loop to match the pattern in the other four files and added a guard against DICOM delimiter tags:

  • (tag >>> 16) != 0xFFFE — rejects stale delimiter tags (Item, ItemDelimitationItem, SeqDelimitationItem) that should never be written as standalone elements
  • tag != 0xFFFAFFFA / tag != 0xFFFCFFFC — filters Digital Signatures Sequence and Data Set Trailing Padding, matching the other files

After this change the output was valid DICOM.

…lement,

the post-pixels loop wrote a stale SeqDelimitationItem (fffe,e0dd) left over
from the encapsulated pixel-skip logic. Restructured the loop to match the
other DICOM processors and filter out FFFE-group delimiter tags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant