Skip to content

Fix/cstore implicit vr little endian - #60

Open
luis-godinho wants to merge 2 commits into
devfrom
fix/cstore-implicit-vr-little-endian
Open

luis-godinho wants to merge 2 commits into
devfrom
fix/cstore-implicit-vr-little-endian

Conversation

@luis-godinho

@luis-godinho luis-godinho commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

CStoreService.normalizeToPs310 created the DicomOutputStream with the negotiated transfer syntax. But PS3.10 requires File Meta Information (FMI) to always be written in Explicit VR Little Endian. With Implicit VR LE, writeFileMetaInformation() threw IllegalStateException before the dataset was written.
This PR aims to address issue #56

Fix

Always create the stream in Explicit VR LE. DicomOutputStream.writeDataset(fmi, attrs) writes the FMI correctly, then switches to the transfer syntax declared in the FMI before writing the dataset — so the image data keeps its original transfer syntax.

Tests added

  • CStoreServiceTest.returnsSuccessForImplicitVRLittleEndian — unit test exercising the fix path.
  • DimseCStoreSCPIntegrationTest — end-to-end network test: embedded SCP server + real SCU client over TCP sending C-STORE-RQ with Implicit VR LE; verifies C-STORE-RSP returns Success.

normalizeToPs310 created DicomOutputStream with the negotiated transfer
syntax, but writeFileMetaInformation requires Explicit VR Little Endian
(PS3.10). With Implicit VR LE this threw IllegalStateException ('Sta6')
and aborted the association.

Always create the stream in Explicit VR LE; DicomOutputStream.writeDataset
writes the FMI in Explicit VR LE then switches to the transfer syntax
declared in the FMI before writing the dataset, so the dataset keeps its
original transfer syntax.

Adds a test covering Implicit VR LE C-STORE (regression for issue #56).
…ssue #56)

DimseCStoreSCPIntegrationTest starts an embedded DimseCStoreServer (SCP)
and connects as a DICOM SCU over TCP, sending a C-STORE-RQ with Implicit
VR Little Endian transfer syntax. Verifies the association completes and
the server returns C-STORE-RSP with status Success.

Reproduces the exact scenario from issue #56: a SCU sending an object in
Implicit VR Little Endian (1.2.840.10008.1.2) via DIMSE C-STORE.
@Enet4 Enet4 added the bug Something isn't working label Oct 19, 2026

@Enet4 Enet4 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I could not do a complete review, but I found at least one thing worth improving.

Comment on lines 324 to +328
try (var fos = new java.io.FileOutputStream(tmpFile.toFile());
DicomOutputStream dos = new DicomOutputStream(fos, transferSyntaxUid)) {
// File Meta Information must always be written in Explicit VR Little Endian
// (PS3.10). DicomOutputStream.writeDataset(fmi, attrs) writes the FMI in Explicit VR LE,
// then switches to the transfer syntax declared in the FMI before writing the dataset.
DicomOutputStream dos = new DicomOutputStream(fos, UID.ExplicitVRLittleEndian)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since we have a (temporary) File at this level, the use of the constructor overload receiving a File is preferred, which makes less room for misuse. Note how this also provides buffered writing.

    try (var dos = new DicomOuputStream(tmpFile.toFile())) {

In any case I admit that a DicomOutputStream(OutputStream) overload would have been useful here. The sequence of constructing a DicomOutputStream with any TS UID other than Explicit VR, and then calling writeDataset with a non-null file meta information group will always fail. I sent this suggestion upstream to the dcm4che project.

@Enet4 Enet4 added the backend Area: dicoogle-next backend (server) label Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Area: dicoogle-next backend (server) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants