BUG: Remove invalid characters from DICOM strings with unsupported character encoding #968
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When DICOM strings could not be decoded (because an unsupported encoding was used) then it was assumed to be encoded as Latin1.
This led to incorrect special characters appearing in the output and in some cases even invalid UTF8 string (causing data corruption - see https://discourse.slicer.org/t/re-failure-to-opening-saved-work/17473/5).
As a workaround, to make decoding issues more visible and avoid having random non-ASCII characters appearing in the output, we replace non-ASCII characters by '?'.
As a proper solution, DCMTK could be used to convert from all DICOM standard encodings. However, for this DMTK must be built with iconv, which seems to be quite complicated (mostly DCMTK's build system handles third-party dependencies in unusual way). Since non-supported encodings are very rare (just a few ISO 2022 IR encodings) it is probably not a serious limitation. For example, DCM4CHEE does not support any of the ISO 2022 IR encodings (https://dcm4chee-arc-cs.readthedocs.io/en/latest/charsets.html).