You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
You got a point. the code already tries to serialize the decimal. And in case the lenth of 16 characters is exceeded, the serialization is redone using the G11 formatter. But this G11 can still be too long.
Your suggestion to use G10 as formatter would be perfect solution.
Would you mind to make a PR containing this change and adding a method to unittests to add the number you posted above?
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
causes this exception to be thrown:
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
tovalueString = value.ToString("G10", CultureInfo.InvariantCulture);
Environment
Fellow Oak DICOM version: 5.0.2.4
OS: Windows 10 x64
Platform: .NET Framework 4.8
The text was updated successfully, but these errors were encountered: