Skip to content

fix: keep untilTag and NumberOfFrames out of AsyncDicomReader sequence items - #657

Merged
wayfarer3130 merged 3 commits into
dcmjs-org:masterfrom
MikeFTV:fix/async-reader-sequence-state
Nov 25, 2026
Merged

wayfarer3130 merged 3 commits into
dcmjs-org:masterfrom
MikeFTV:fix/async-reader-sequence-state

Conversation

@MikeFTV

@MikeFTV MikeFTV commented Nov 25, 2026

Copy link
Copy Markdown

Why

AsyncDicomReader applies state of the top-level data set inside sequence items, so a file with an Icon Image Sequence (0088,0200), whose item has its own Pixel Data (PS3.3 C.7.6.1.1.6), cannot be read in two cases (#643):

  • With untilTag: "7FE00010", the read stops at the icon's Pixel Data and readSequence throws an Error with an empty message.
  • The NumberOfFrames of the file is used to split the icon's Pixel Data: 2 frames returns two 2-byte frames for a 4-byte icon, 3 frames throws Invalid frame length: 4 for 3 frames.

The sync reader (DicomMessage.readFile) reads these files correctly.

What changes

  • readSequence no longer passes untilTag and includeUntilTagValue to the items, so untilTag stops the read at the top level only.
  • A sequenceDepth counter and getNumberOfFrames() give 1 for Pixel Data inside a sequence item. NumberOfFrames is tracked in listener.information for the top-level data set only, so the nested value was never known. The three places that read it (readCompressed, readUncompressed, readUncompressedBitFrame) use the method.
  • The error for a tag that is neither an item nor a sequence delimitation item now names the tag.
  • docs/AsyncDicomReader-skill.md: untilTag is for the top level.

Not changed: listener.information.rows, columns and bitsAllocated also come from the top level. They are read only for multi-frame or 1-bit Pixel Data, which an icon does not have in this fix. A nested 1-bit icon is not covered. The readTagHeader(syntax, options) call mentioned in the issue is already readTagHeader({...options, readSyntax}) on master.

This is on master, where the issue was reported (0.52.3). packages/legacy/src/AsyncDicomReader.js on 1.0-beta has the same code; it needs the same change, as with the other master fixes listed in #649.

Fixes #643

Tests

New test/async-sequence-item-state.test.js builds the file of the issue (Icon Image Sequence with Pixel Data in the item) and checks:

  • untilTag: "7FE00010" reads the icon whole and stops before the Pixel Data of the data set (the sync reader gives the same icon);
  • the icon is one frame with NumberOfFrames 1 (absent), 2 and 3, and the Pixel Data of the data set is still split in 2 or 3 frames.

Both tests fail on master (empty-message Error, then [[[1,2]],[[3,4]]] instead of one frame) and pass with the change.

  • npx jest test/async-sequence-item-state.test.js: 2 passed
  • pnpm test: 33 suites, 435 tests passed (the baseline master has 433)
  • pnpm run format:check: passed
  • npx eslint "src/**/*.js" "test/**/*.js": no errors

…e items

untilTag now applies to the top-level data set only, and Pixel Data inside a
sequence item (an Icon Image Sequence item) is one frame instead of being
split with the NumberOfFrames of the file. The error for a tag that is not
an item in a sequence now names the tag.
@netlify

netlify Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for dcmjs2 ready!

Name Link
🔨 Latest commit d702e43
🔍 Latest deploy log https://app.netlify.com/projects/dcmjs2/deploys/6b06ecf0a5c0c1ac154d9d84
😎 Deploy Preview https://deploy-preview-657--dcmjs2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@wayfarer3130
wayfarer3130 merged commit d236313 into dcmjs-org:master Nov 25, 2026
8 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.53.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

wayfarer3130 added a commit that referenced this pull request Nov 25, 2026
Record master (d236313) as a parent with -s ours; the tree stays the 1.0-beta tree. Master fixes #657, #622, #510, #625 and #632 are not in 1.x and need ports.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130 added a commit that referenced this pull request Nov 25, 2026
… sequence items (port of #657) (#666)

1.0 port of #657 (commit d236313), fixes #643.

AsyncDicomReader applied top-level state inside sequence items. With an
Icon Image Sequence (0088,0200), untilTag "7FE00010" stopped at the
icon's Pixel Data and readSequence threw an empty Error, and the
NumberOfFrames of the file split the icon's Pixel Data.

- readSequence reads the items without untilTag and includeUntilTagValue.
- A sequenceDepth counter and getNumberOfFrames() give 1 frame inside an
  item; readCompressed, readUncompressed and readUncompressedBitFrame use it.
- The error for an unexpected tag in a sequence names the tag.
- docs/AsyncDicomReader-skill.md: untilTag is for the top level.

Rows, Columns and BitsAllocated still come from the top level, as in #657.

test/async-sequence-item-state.test.js builds the file with
createSampleDicom; both tests fail on 1.0-beta and pass with the change.
The bundle-size ceilings rise to x1.091 and x1.073 (measured x1.09044,
x1.07212).

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsyncDicomReader: untilTag and NumberOfFrames leak into sequence items

2 participants