[PATCH] Fixed issue with delimiters being converted.
authorJoerg Riesmeier <dicom@jriesmeier.com>
Wed, 8 Nov 2023 10:38:54 +0000 (11:38 +0100)
committerÉtienne Mollier <emollier@debian.org>
Sat, 18 Jan 2025 15:30:29 +0000 (16:30 +0100)
Fixed issue with delimiter character "\" being converted when converting
a DICOM dataset that uses a Specific Character Set of "ISO 2022 IR 13\ISO
2022 IR 87" to UTF-8. The delimiter "\" was incorrectly converted to the
Yen sign when processing the value of an "LO" data element that contains
multiple values but does not use any escape sequences. This issues has
been fixed now by always treating the delimiters in a special way.

Thanks to Mathieu Malaterre <mathieu.malaterre@gmail.com> for the report
and David Gobbi <david.gobbi@gmail.com> for the analysis and testing.

Gbp-Pq: Name da5370947226783ce3548bf1e5b7112fac70de46.patch

dcmdata/libsrc/dcspchrs.cc

index c327a1aa823425f47489b4d5ed196442129a8032..69d14a1601643b374c14f969a171f716dd333ead 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *
- *  Copyright (C) 2011-2022, OFFIS e.V.
+ *  Copyright (C) 2011-2023, OFFIS e.V.
  *  All rights reserved.  See COPYRIGHT file for details.
  *
  *  This software and supporting documentation were developed by
@@ -548,8 +548,9 @@ OFCondition DcmSpecificCharacterSet::convertString(const char *fromString,
                                                    const OFString &delimiters)
 {
     OFCondition status = EC_Normal;
-    // check whether there are any code extensions at all
-    if (EncodingConverters.empty() || !checkForEscapeCharacter(fromString, fromLength))
+    // check whether there are or could be any code extensions
+    const OFBool hasEscapeChar = checkForEscapeCharacter(fromString, fromLength);
+    if (EncodingConverters.empty() || (!hasEscapeChar && delimiters.empty()))
     {
         DCMDATA_DEBUG("DcmSpecificCharacterSet: Converting '"
             << convertToLengthLimitedOctalString(fromString, fromLength) << "'");
@@ -564,10 +565,11 @@ OFCondition DcmSpecificCharacterSet::convertString(const char *fromString,
         } else {
             DCMDATA_DEBUG("DcmSpecificCharacterSet: Converting '"
                 << convertToLengthLimitedOctalString(fromString, fromLength)
-                << "' (with code extensions and delimiters '" << delimiters << "')");
+                << "' (with " << (hasEscapeChar ? "code extensions and " : "")
+                << "delimiters '" << delimiters << "')");
         }
-        // code extensions according to ISO 2022 used, so we need to check for
-        // particular escape sequences in order to switch between character sets
+        // code extensions according to ISO 2022 (possibly) used, so we need to check
+        // for particular escape sequences in order to switch between character sets
         toString.clear();
         size_t pos = 0;
         // some (extended) character sets use more than 1 byte per character