From eed6e48e0c5add6f8bb06dccc273d78ba1f0efd6 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 10 Sep 2024 17:12:27 +0100 Subject: [PATCH] don't trim spaces from numeric fields We were accidentally trimming spaces characters from the end of numeric fields. See https://github.com/ImagingDataCommons/libdicom/issues/89 Thanks @y-baba-isb --- CHANGELOG.md | 1 + src/dicom-parse.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f8ae01..072ef48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * fix build with uthash \< 2.3.0 [bgilbert] * explicitly fail if macOS universal build is attempted [bgilbert] * better handling of implicit mode in dcm-dump [jcupitt] +* better handling of trailing spaces in string values [y-baba-isb] ## 1.1.0, 28/3/24 diff --git a/src/dicom-parse.c b/src/dicom-parse.c index 6a8b298..5865b9a 100644 --- a/src/dicom-parse.c +++ b/src/dicom-parse.c @@ -616,12 +616,12 @@ static bool parse_element_body(DcmParseState *state, } value[length] = '\0'; - if (length > 0) { - if (vr != DCM_VR_UI) { - if (isspace(value[length - 1])) { - value[length - 1] = '\0'; - } - } + if (length > 0 && + (vr_class == DCM_VR_CLASS_STRING_SINGLE || + vr_class == DCM_VR_CLASS_STRING_MULTI) && + vr != DCM_VR_UI && + isspace(value[length - 1])) { + value[length - 1] = '\0'; } if (size > 0 && state->big_endian) {