Repository navigation
fix(legacy): read a UN element that holds a sequence as Implicit VR LE (port of #496) - #658
Merged
Merged
Conversation
…E (port of #496) PS3.5 §6.2.2: an Explicit VR element with VR UN and a defined length, whose value starts with the item tag (FFFE,E000), holds a sequence in Implicit VR Little Endian. - legacy DicomMessage._readTag and AsyncDicomReader read such a value as SQ (shared isUnSequenceValue). - parser fromPart10Stream (and fromPart10) emit it as a sequence. - core Tag.write writes a UN whose values are all item objects as SQ with undefined length. - bundle-size ceilings 1.085 and 1.067. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 25, 2026
Merged
…tem check
- core: isUnSequenceValue (dictionary VR SQ or no entry, item tag,
first item length undefined or within the value) and isItemDictLike,
one copy for the legacy sync, legacy async and event-stream readers.
- legacy sync reader: read the items as little endian in an Explicit VR
Big Endian body (the items were lost).
- Tag.write: a UN is written as SQ only when every value is an item
dataset; { InlineBinary } and { BulkDataURI } stay UN.
- parser: JSDoc and AD-1 text name the §6.2.2 exception.
- docs: NAT-U-BIN-6 and NAT-I-BIN-3.
- tests: Explicit VR Big Endian, bad item length, dictionary VR OB,
binary references on write.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-496-un-sequence # Conflicts: # test/bundle-size.test.js # test/sync-async-parser-equivalency.test.js
|
🎉 This PR is included in version 1.0.0-beta.19 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is the 1.0 port of #496 from 0.x.
Summary
PS3.5 §6.2.2 says that a
UNelement that holds a sequence uses Implicit VR Little Endian. An Explicit VR file can have such an element with a defined length. The value of that element starts with the item tag (FFFE,E000), which is the bytesFE FF 00 E0. This PR reads that value as anSQin all 1.x read paths. This PR also writes aUNwith item datasets asSQ.Detection rule (read)
A reader reads an Explicit VR
UNvalue as a sequence only when all of these conditions are true:SQ, or the tag has no dictionary entry (for example a private tag).FFFFFFFF, or the first item length is not more than the value length minus 8.A value that fails the rule stays
UNbytes, as on1.0-beta. For example, a private value with the item tag and an item length that is too large staysUN. A standard tag with the dictionary VROB, sent asUN, keeps itsOBbytes.The items are Implicit VR Little Endian, also in an Explicit VR Big Endian file.
Writer rule
Tag.writewrites aUNasSQwith undefined length only when every value is an item dataset. An item dataset is an object whose keys are all tags, for example"00100010". AUNwith{ InlineBinary }or{ BulkDataURI }staysUN.Cause
DicomMessage._readTagandAsyncDicomReader) read the value with the Explicit VR syntax of the file. A private tag stayedUNwith binary data. A standard tag with a dictionary VR ofSQ, for example (0018,100A), gave items with wrong values.fromPart10Stream, andfromPart10, which uses it) had the same problem. The fix for issue Invalid tag in sequence : Unable to parse MR Dicom file in dcmjs. Cornerstone able to parse and works fine #363 covers only aUNwith undefined length. A private tag gaveUNwith an empty object. A standard tag with a dictionary VR ofSQcaused an error.Tag.writein@dcmjs-org/corewrote aUNwith item objects as aUNwith length 0. The writer lost the items.Changes
packages/core/src/utilities/unSequence.js(new):isUnSequenceValue(view, offset, length, vr)holds the detection rule.isItemDictLike(v)holds the item dataset check. The file uses the existingSEQUENCE_ITEM_TAGandisBinaryData.@dcmjs-org/coreexports both functions. The three readers and the writer use this one copy.packages/legacy/src/DicomMessage.js:_readTagkeeps the VR from the stream, before the dictionary override. When that VR isUNandisUnSequenceValueis true,_readTagreads the value asSQwith Implicit VR LE._readTagalso sets the stream to little endian for the items, and restores the endian after the element.packages/legacy/src/AsyncDicomReader.js:readTagHeaderdoes the same check, and givessequenceReadSyntaxin the header.readSequence,readandreadSingleread the items with that syntax throughoptions.readSyntax.readSequencealso passes the options correctly toreadTagHeader. Before, it passed the syntax string as the options.packages/parser/src/eventStream/fromPart10Stream.js:parseOneElementdoes the same check, and emits the sequence with the body syntax set to Implicit VR LE.withImplicitLEsets the syntax and restores it after the sequence. The JSDoc ofparseOneElementnames the §6.2.2 exception.packages/parser/src/core/decodeCore.js: the AD-1 contract text names the §6.2.2 exception.packages/parser/src/eventStream/emit.js: usesisItemDictLikefrom@dcmjs-org/core. The local copy is removed.packages/core/src/Tag.js:Tag.writeusesisItemDictLikefor the writer rule.docs/specs/naturalized-dataset.md: new user requirement NAT-U-BIN-6. NAT-U-BIN-1 points to NAT-U-BIN-6. New implementation requirement NAT-I-BIN-3.test/helper/ps352UnSequenceFixture.js: fixture with the §6.2.2 bytes. The fixture can write an Explicit VR Big Endian file.test/sync-async-parser-equivalency.test.js: new tests. The read tests use the sync reader, the async reader,fromPart10andfromPart10Stream:DicomMessage._readTagreads the element asSQ.SQin all readers.SQin all readers, and the element after the sequence reads correctly.UNwith the item tag and an item length that is too large staysUNwith the same bytes.OB, sent asUNwith the item tag, keeps its bytes.SQandFFFFFFFF.UNwith item datasets writes asSQwith undefined length, in Explicit VR LE and in Implicit VR LE.UNwith{ InlineBinary }or{ BulkDataURI }writes asUN.test/bundle-size.test.js: each ceiling is the measured ratio, rounded up to 0.001: 1.086 (dcmjs.js) and 1.069 (dcmjs.es.js). The measured ratios after the merge of1.0-betaare 1.0858 and 1.0684.Verified
1.0-beta, 6 of the 9 first tests insync-async-parser-equivalency.test.jsfailed.OB,{ InlineBinary }and{ BulkDataURI }. After the fixes, all 13 tests of the §6.2.2 group pass.origin/1.0-beta:npx jest --runInBandonbundle-size,sync-async-parser-equivalency,SequenceOfItems,defined-length-sequence,fromPart10Stream,fromPart10andlossless-read-writegives 248 passed and 1 skipped.streamEquivalence,crossSource,Part10Writer,NaturalizedListener,export,data-options,data-encodingand the files above) gave 417 passed and 1 skipped.eslint,prettier --checkandpnpm run buildpass.Not ported from #496
loglevelexternal in the ES build ofrollup.config.mjs. This change is not part of the §6.2.2 fix, and it is out of scope for this port.data.test.jstest of_readTagis insync-async-parser-equivalency.test.jsin this PR, with the other §6.2.2 tests.Maintainer edits
UNsequence in Explicit VR Big Endian. Before, the reader lost the items.SQor with no dictionary entry. The rule also checks the first item length. Before, a value that started with the item tag but was not a sequence caused an error in the sync reader and in the event-stream reader.UNasSQonly for item datasets. Before, the writer wrote{ InlineBinary }and{ BulkDataURI }as anSQwith a junk item.isUnSequenceValueandisItemDictLikeare in@dcmjs-org/core, with one copy for all readers and the writer.parseOneElementJSDoc and the AD-1 contract text name the §6.2.2 exception.docs/specs/naturalized-dataset.md. The change is a correction for an edge case, not a breaking change, sodocs/BREAKING_CHANGES.mddoes not change.origin/1.0-beta(fix: keep empty sequence items when reading (port of #608) #660, fix(orientation): allocate matrix transform output with the input type (port of #602) #661, fix(normalizers): normalize multiframe datasets missing functional groups (port of #603) #662), and new bundle ceilings.🤖 Generated with Claude Code