Skip to content

fix: bring AsyncDicomReader into the xs meta-VR resolution contract - #544

Merged
awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/finding-25-async-xs-contract
Sep 30, 2026
Merged

awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/finding-25-async-xs-contract

Conversation

@awatson1978

Copy link
Copy Markdown
Collaborator

The async reader was the one read path left outside the "xs" contract that PR #537 established: it read every "xs"-typed element as unsigned, so an async read and a sync read of the same signed pixel data disagreed on both the VR and the values.

Quick recap of the contract. The dictionary meta-VR "xs" means "US or SS" — unsigned or signed 16-bit — and per PS3.5 the right choice hangs on PixelRepresentation (0028,0103): signed when it's 1, unsigned otherwise. PR #537 taught the eager reader to thread that value through to _readTag and resolve "xs" accordingly. AsyncDicomReader never got the same treatment; this is review finding 25.

What was actually in the async reader was worse than a missing feature — it was a dead branch. readTagHeader did a bare vrType = elementData.vr whenever the tag was in the dictionary, so "xs" sailed straight into createByTypeString("xs") and fell back to US every time. The vrType == "xs" check sat on the unknown-tag path, where vrType is always undefined, so it could never run — and even if it had, its signedness test was inverted (pixelRepresentation === 0 meaning signed). The explicit-VR UN fallback had the same gap.

When it bites: any Implicit VR LE file with PixelRepresentation 1 and a signed value in an "xs" tag like (0028,0106) SmallestImagePixelValue. The two readers returned different answers for the same bytes:

// PixelRepresentation = 1 (signed), SmallestImagePixelValue = -2
const sync = DicomMessage.readFile(buffer).dict;
sync["00280106"].vr;     // "SS"  (since #537)
sync["00280106"].Value;  // [-2]

// before this fix, the async reader disagreed:
const { dict } = await reader.readFile();
dict["00280106"].vr;     // "US"
dict["00280106"].Value;  // [65534]  — the unsigned reinterpretation

The fix shares #537's code path rather than copying it: the resolution now lives in one helper, DicomMessage.resolveXsVrType(pixelRepresentation), used by the eager reader's two sites and by readTagHeader's implicit and explicit-UN branches alike. The async side feeds it the PixelRepresentation value the listener's information filter already tracks (which is what the dead branch was reaching for all along), and the dead branch itself is gone — the same deletion #537 made in DicomMessage.

Two tests pin it in test/issues/issue368-xs-ox-vr-resolution.test.js, the suite that owns the xs contract: an async read with PixelRepresentation 1 must return SS with the negative values intact and agree element-for-element with the sync read, and the PixelRepresentation 0 case must agree on US. The signed one failed with exactly the 65534-for--2 disagreement above before the fix. Full suite: 612 passed, 20 skipped.

The same dead branch, inverted test and all, is on master's AsyncDicomReader verbatim — so like #537, this looks applicable to master as a 0.52.x hotfix.

🤖 Generated with Claude Code

…epresentation contract

The async reader took the raw dictionary VR "xs" without resolving it,
so every xs element fell back to US and signed pixel-value tags came
back as their unsigned reinterpretation (-2 read as 65534) while the
sync reader (fixed for issue #368) returned -2. The old xs branch in
readTagHeader was dead — it sat on the unknown-tag path where vrType is
always undefined — and its signedness test was inverted besides.

Both readers now resolve xs through one shared helper,
DicomMessage.resolveXsVrType (SS when PixelRepresentation is 1, US
otherwise), on the implicit path and the explicit-VR UN fallback alike.
The async reader feeds it the PixelRepresentation value the listener's
information filter already tracks. Review finding 25.

Co-Authored-By: Claude Fable 5 <[email protected]>
@awatson1978
awatson1978 merged commit ded47ea into release/1.0-beta-core Sep 30, 2026
8 checks passed
@awatson1978
awatson1978 deleted the core/finding-25-async-xs-contract branch September 30, 2026 11:28
awatson1978 added a commit that referenced this pull request Sep 30, 2026
…ne and event-stream findings

Engine findings 1/3/4/24/25/27/28/32 landed as PRs #544-#551; the
writers wave (#552-#557) fixed 5/6/7/11/22/23 in the ports and retired
14 by trimming the video factories from the core facade. Master
verdicts are now verified against origin/master, not just triaged.

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant