From 9ecec7671ded01648354e617972d0f1f9a9576b9 Mon Sep 17 00:00:00 2001 From: Joerg Riesmeier <dicom@jriesmeier.com> Date: Mon, 22 Apr 2024 12:11:11 +0200 Subject: Fixed wrong error handling (previous commit). Bug-Debian: https://bugs.debian.org/1070207 Forwarded: not-needed Fixed wrong error handling introduced with the previous commit. --- dcmrt/libsrc/drttypes.cc | 6 +++--- dcmsr/libsrc/dsrtypes.cc | 32 ++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 15 deletions(-) --- a/dcmrt/libsrc/drttypes.cc +++ b/dcmrt/libsrc/drttypes.cc @@ -210,11 +210,11 @@ { DcmStack stack; OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/); - if (result.good() && (dynamic_cast<DcmElement*>(stack.top()) != nullptr)) + if (result.good()) { - DcmElement *element = OFstatic_cast(DcmElement *, stack.top()); - if (element != NULL) + if (dynamic_cast<DcmElement*>(stack.top()) != nullptr) { + DcmElement *element = OFstatic_cast(DcmElement *, stack.top()); if (checkElementValue(*element, vm, type, result, moduleName)) result = element->getOFString(stringValue, 0); else --- a/dcmsr/libsrc/dsrtypes.cc +++ b/dcmsr/libsrc/dsrtypes.cc @@ -1176,13 +1176,17 @@ DcmStack stack; const DcmTagKey tagKey = delem.getTag(); OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/); - if (result.good() && (dynamic_cast<DcmElement*>(stack.top()) != nullptr)) + if (result.good()) { - /* copy object from search stack */ - result = delem.copyFrom(*stack.top()); - /* we need a reference to the original element in order to determine the SpecificCharacterSet */ - if (!checkElementValue(OFstatic_cast(DcmElement *, stack.top()), tagKey, vm, type, result, moduleName, acceptViolation)) - result = SR_EC_InvalidValue; + if (dynamic_cast<DcmElement*>(stack.top()) != nullptr) + { + /* copy object from search stack */ + result = delem.copyFrom(*stack.top()); + /* we need a reference to the original element in order to determine the SpecificCharacterSet */ + if (!checkElementValue(OFstatic_cast(DcmElement *, stack.top()), tagKey, vm, type, result, moduleName, acceptViolation)) + result = SR_EC_InvalidValue; + } else + result = EC_CorruptedData; } /* the element could not be found in the dataset */ else if (!checkElementValue(delem, vm, type, result, moduleName, acceptViolation)) @@ -1201,13 +1205,17 @@ { DcmStack stack; OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/); - if (result.good() && (dynamic_cast<DcmElement*>(stack.top()) != nullptr)) + if (result.good()) { - DcmElement *delem = OFstatic_cast(DcmElement *, stack.top()); - /* we need a reference to the original element in order to determine the SpecificCharacterSet */ - if (!checkElementValue(delem, tagKey, vm, type, result, moduleName, acceptViolation)) - result = SR_EC_InvalidValue; - delem->getOFString(stringValue, 0); + if (dynamic_cast<DcmElement*>(stack.top()) != nullptr) + { + DcmElement *delem = OFstatic_cast(DcmElement *, stack.top()); + /* we need a reference to the original element in order to determine the SpecificCharacterSet */ + if (!checkElementValue(delem, tagKey, vm, type, result, moduleName, acceptViolation)) + result = SR_EC_InvalidValue; + delem->getOFString(stringValue, 0); + } else + result = EC_CorruptedData; } else { if ((type == "1") || (type == "2")) {