8000 IndexOutOfRangeException while saving dicom file when Specific Character Set (0008,0005) is empty · Issue #1879 · fo-dicom/fo-dicom · GitHub 8000
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
IndexOutOfRangeException while saving dicom file when Specific Character Set (0008,0005) is empty #1879
Closed
@gunjitchhhatwal

Description

@gunjitchhhatwal

Describe the bug
An exception is thrown when FellowOakDicom.DicomFile.SaveAsync is called for a dicom dataset having "Value 1 of the Attribute Specific Character Set (0008,0005)" = an empty string.

System.IndexOutOfRangeException

at FellowOakDicom.DicomEncoding.EncodeString(String value, Encoding[] encodings, Boolean isPersonName)
at FellowOakDicom.DicomStringElement.StringToBytes()
at FellowOakDicom.IO.Buffer.LazyByteBuffer.get_Size()
at FellowOakDicom.IO.Writer.DicomWriter.OnElementAsync(DicomElement element)
at FellowOakDicom.DicomDatasetWalker.DoWalkAsync(IDicomDatasetWalker walker, Queue`1 items)
at FellowOakDicom.IO.Writer.DicomFileWriter.WriteDatasetAsync(IByteTarget target, DicomTransferSyntax syntax, DicomDataset dataset, DicomWriteOptions options)
at FellowOakDicom.IO.Writer.DicomFileWriter.WriteAsync(IByteTarget target, DicomFileMetaInformation fileMetaInfo, DicomDataset dataset)
at FellowOakDicom.DicomFile.SaveAsync(Stream stream, DicomWriteOptions options)

To Reproduce

public async static Task TestDicom()
{
    var dicom = DicomFile.Open("test.dcm"); // any valid dcm file with an attribute having a string value (e.g. VR = SH or LO). E.g. Accession Number

    dicom.Dataset.Add(DicomTag.SpecificCharacterSet, ""); // add (0008,0005) tag with empty string as value

    Stream stream = new MemoryStream();

    await dicom.SaveAsync(stream);// try to save the file to a stream, throws exception here
}

Expected behavior
Per DICOM standard, an empty value 1 of this attribute essentially represents the default character repertoire. One should be able to save the file to the stream as if the specific character set tag was not present at all.

https://dicom.nema.org/medical/dicom/current/output/chtml/part05/chapter_6.html

"The replacement Character Repertoire specified in Value 1 of the Attribute Specific Character Set (0008,0005) (or the Default Character Repertoire if Value 1 is empty) may be further extended with additional Coded Character Sets"

Screenshots or test DICOM files
image

Environment
Fellow Oak DICOM version: 5.1.4
OS: (e.g. Windows 11 x64)
Platform: .NET 6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0