Skip to content

[encoding] Fix length serialization of Explicit VR TS for new VRs#744

Merged
Enet4 merged 2 commits intoEnet4:masterfrom
pgimeno4d:fix-32-bit-lengths-explicit-vr
Mar 5, 2026
Merged

[encoding] Fix length serialization of Explicit VR TS for new VRs#744
Enet4 merged 2 commits intoEnet4:masterfrom
pgimeno4d:fix-32-bit-lengths-explicit-vr

Conversation

@pgimeno4d
Copy link
Copy Markdown
Contributor

Fix the long-format VR encoding according to the standard (closes #739).

In particular, VRs of type UV, SV and OV were not properly serialized. The standard says that when using the Explicit VR transfer syntax, a 16-bit length field applies only to VRs of AE, AS, AT, CS, DA, DS, DT, FL, FD, IS, LO, LT, PN, SH, SL, SS, ST, TM, UI, UL and US (PS3.5 7.1.2), and the rest uses the 32-bit version including a reserved 16-bit field where the old 16-bit length was.

It also says that all new VRs in future versions of the standard will use the long version of the encoding for lengths:

All new VRs defined in future versions of DICOM shall be of the same Data Element Structure as defined in Section 7.1.2 with reserved bytes after the VR and a 32-bit unsigned integer VL (i.e., following the format for VRs such as OB or UT), and may or may not permit Undefined Length.
(PS3.5 6.2)

So, this patch fixes the encoding for the VRs that are not working and prepares the code for possible future VRs.

@Enet4 Enet4 added bug This is a bug A-lib Area: library C-encoding Crate: dicom-encoding labels Feb 23, 2026
@Enet4 Enet4 added this to the DICOM-rs 0.9.1 milestone Mar 3, 2026
Copy link
Copy Markdown
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

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

Excellent! Now it is implemented just as in the standard (2-byte lengths for these specific VRs, 4-byte length for every other VR), with nice test coverage. No concerns from my side. Thank you!

@Enet4 Enet4 merged commit fa3fa4b into Enet4:master Mar 5, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-lib Area: library bug This is a bug C-encoding Crate: dicom-encoding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[encoding] Incorrect serialization of VRs UV, SV and possibly others; transcode() affected

2 participants