Skip to content

feat: Support for VR type "UV" - #488

Merged
wayfarer3130 merged 7 commits into
dcmjs-org:masterfrom
PolarsBear:implement-uv-vr
May 11, 2026
Merged

wayfarer3130 merged 7 commits into
dcmjs-org:masterfrom
PolarsBear:implement-uv-vr

Conversation

@PolarsBear

Copy link
Copy Markdown
Contributor

In accordance with the (not so) new DICOM metadata standards, since 2019a, as stated in PS3.5, section 6.2 (see here), the VR type "UV", or "Unsigned 64 bit Very Long" describes, as one would expect, a 64 bit unsigned integer.

To comply with these standards and avoid interpreting these values as VR type "UN" (Unknown), I offer this contribution.

I attempted to keep things as close to the standard you've set as I could, but, in case of any insatisfaction, I am more than capable of reworking the code herein suggested.

The tests leave quite a bit to be desired. I must admit testing is not my greatest strong suit. Basic testing is in place for reading and writing, but more in-depth tests with real DICOM datasets would be welcome.

I couldn't find any documentation as to how I should write the Pull Request, so I hope this is acceptable

(Also, my first Pull Request, so I ask you to forgive me if something here isn't up to standard)

@netlify

netlify Bot commented Apr 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for dcmjs2 ready!

Name Link
🔨 Latest commit 5590b1d
🔍 Latest deploy log https://app.netlify.com/projects/dcmjs2/deploys/6a01ccb1da3827000813d175
😎 Deploy Preview https://deploy-preview-488--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.

@pieper
pieper requested a review from wayfarer3130 April 14, 2026 12:49

@pieper pieper left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me, thanks for the contribution 👍

I'd like another set of eyes though, so maybe @wayfarer3130 can take a look.

}

readBytes(stream) {
return stream.readBigUint64();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is incorrect on two counts - it doesn't allow repeated UV values, and it isn't returning an array. Just pushing a change now to fix that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the binary vrs will re-run the read/write multiple times, so I've just added UV to the binary VRs list.

@wayfarer3130 wayfarer3130 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the issue with the encoding type and added some equivalency tests.

@wayfarer3130
wayfarer3130 merged commit 91e4771 into dcmjs-org:master May 11, 2026
11 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.51.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

wayfarer3130 added a commit that referenced this pull request Nov 24, 2026
* fix(DicomMessage): parse UN-encoded sequences using Implicit VR LE per PS3.5 §6.2.2

When an Explicit VR file encodes a sequence element with VR=UN and a
defined length, DICOM PS3.5 §6.2.2 requires that its items be parsed
using Implicit VR Little Endian regardless of the file's transfer syntax.

Without this fix, dcmjs tried to interpret the item bytes as Explicit VR,
emitted 'Invalid vr type ( - using UN', stored the value as [{}], and then
on write inflated the element length to ~843 MB (the 843 MB inflation bug
reported for files containing UDISequence (0018,100A)).

The fix records the literal wire VR before any dictionary override
(wireVrType), then after reading the length checks whether the payload
starts with the FFFE item-delimiter group bytes (FE FF in LE). If so,
the element is re-typed as SQ and the recursive item read is forced to
IMPLICIT_LITTLE_ENDIAN.

Adds a regression test that builds a hand-crafted Explicit VR buffer with
UDISequence (0018,100A) encoded as UN and verifies the inner
UniqueDeviceIdentifier (0018,1009) value is correctly recovered.

* fix(sr): avoid injecting options into Template ContentSequences (#494)

* fix: fix charset handling in async reader to match the sync reader utf-8 conversion(#493)

The sync reader sets the character set to utf-8 to match the internal conversion it has performed.

* build(deps): bump @babel/plugin-transform-modules-systemjs from 7.23.3 to 7.29.4 via bumping to preset-env 7.29.5 (#495)

* build(deps): bump @babel/plugin-transform-modules-systemjs

Bumps [@babel/plugin-transform-modules-systemjs](https://github.com/babel/babel/tree/HEAD/packages/babel-plugin-transform-modules-systemjs) from 7.23.3 to 7.29.4.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.29.4/packages/babel-plugin-transform-modules-systemjs)

---
updated-dependencies:
- dependency-name: "@babel/plugin-transform-modules-systemjs"
  dependency-version: 7.29.4
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>

* build(deps-dev): bump @babel/preset-env to 7.29.5

Pins @babel/preset-env to an exact 7.29.5 in package.json (was
^7.16.11, resolving to 7.23.8 in the lockfile) and refreshes
yarn.lock. This supersedes the Dependabot indirect bump of
@babel/plugin-transform-modules-systemjs from 7.23.3 to 7.29.4 by
updating the parent that pulls it in, so the new plugin version is
picked up naturally without a resolutions override.

Co-authored-by: Cursor <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bill Wallace <[email protected]>
Co-authored-by: Cursor <[email protected]>

* feat: Support for VR type "UV"  (#488)

* feat(SplitDataView): Add get / set support for BigUint64

* feat(BufferStream): Add read / write support for BigUint64

* feat(ValueRepresentation): Add support for VR type "UV" (Unsigned 64 bit Very Long)

* feat(writeBufferStream-test): Add basic read / write tests for BigUint64

Admits further tests, in fact, leaves much to be desired

* fix: Formatting and add UV to binary VRs

* format

---------

Co-authored-by: Bill Wallace <[email protected]>

* fix: avoid reading data once untilTag is encountered (#490)

* fix: Async handling, and add full test for this

* build: make loglevel an external of the ES build

The ES build now imports loglevel instead of inlining it, so one
loglevel instance can be shared with the host application and other
libraries. The UMD builds keep loglevel bundled for <script> users.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: check the full item tag before a UN value is read as a sequence

- Check all 4 bytes of the item tag FE FF 00 E0 (FFFE,E000) and a length
  of at least 8 in one shared isUnSequenceValue() used by both parsers.
  A UN value that fails the check stays UN.
- Use the same !implicit condition in the sync and async parsers.
- Test a private UN sequence, a FE FF value that stays UN, and a sync
  write round trip.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: write a UN element whose value is a list of items as SQ

A UN element with item objects as Value (for example, from a naturalized
or JSON dataset) now goes through the SQ writer: VR SQ in Explicit VR,
a normal sequence in Implicit VR, and undefined length for the sequence
and the items. Before, the write threw. A UN with binary values stays UN.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Dmitry Belozerov <[email protected]>
Co-authored-by: Igor Octaviano <[email protected]>
Co-authored-by: Luboš Doležel <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Lars von Wangenheim <[email protected]>
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.

3 participants