8000 Some decimal values are converted to too long decimal string and fails validation · Issue #1454 · fo-dicom/fo-dicom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Some decimal values are converted to too long decimal string and fails validation #1454
Closed
@magla42

Description

@magla42

Describe the bug
There are corner cases of decimal values that are not converted to a valid VR=DS value, causing fo-dicom to throw a validation exception.

To Reproduce
The code

var dataset = new DicomDataset();
dataset.Add(DicomTag.TableTopLateralPosition, -12345678901234.1m);

causes this exception to be thrown:

FellowOakDicom.DicomValidationException : Content "-1.2345678901E+13" does not validate VR DS: value exceeds maximum length of 16 characters
at FellowOakDicom.DicomValidation.ValidateDS(String content)

The example is of course completely bonkers in practice and I have no use case for when this would actually happen, but the fact that there exists valid decimal values that can not be converted to a valid DS attribute is at least slightly worrying.

Expected behavior
For a decimal to always be converted to a valid Decimal String. In this case, e.g., "-1.23456789E+13"

One solution could for example be to change the line
valueString = value.ToString("G11", CultureInfo.InvariantCulture);
in DicomDecimalString.ToDecimalString to
valueString = value.ToString("G10", CultureInfo.InvariantCulture);

Environment
Fellow Oak DICOM version: 5.0.2.4
OS: Windows 10 x64
Platform: .NET Framework 4.8

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