# HG changeset patch # User Sebastien Jodogne # Date 1783417599 -7200 # Node ID 7c518a774b7602b86a033f06ec95d430047a6212 # Parent c9b7dcda2d08048392a4c9b5f88a15f3b76599b9 allow empty arrays diff -r c9b7dcda2d08 -r 7c518a774b76 OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp --- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp Tue Jul 07 11:38:21 2026 +0200 +++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp Tue Jul 07 11:46:39 2026 +0200 @@ -734,8 +734,7 @@ { DcmAttributeTag& e = dynamic_cast(element); - if (e.getUint16Array(content_).good() && - content_ != NULL) + if (e.getUint16Array(content_).good()) { if (element.getLength() % sizeof(Uint16) != 0) { @@ -743,6 +742,12 @@ } size_ = static_cast(element.getLength()) / sizeof(Uint16); + if (size_ != 0 && + content_ == NULL) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + if (size_ % 2 != 0) { throw OrthancException(ErrorCode_BadFileFormat); @@ -777,6 +782,8 @@ virtual void ReadValue(std::string& value, uint64_t index) const ORTHANC_OVERRIDE { + assert(valid_); + assert(index < size_); value = GetTag(index).Format(); } @@ -818,8 +825,7 @@ **/ DcmFloatingPointSingle& e = dynamic_cast(element); - if (e.getFloat32Array(content_).good() && - content_ != NULL) + if (e.getFloat32Array(content_).good()) { if (element.getLength() % sizeof(Float32) != 0) { @@ -827,6 +833,12 @@ } size_ = static_cast(element.getLength()) / sizeof(Float32); + if (size_ != 0 && + content_ == NULL) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + valid_ = true; } } @@ -846,6 +858,7 @@ uint64_t index) const ORTHANC_OVERRIDE { assert(valid_); + assert(index < size_); value = boost::lexical_cast(content_[index]); } @@ -890,8 +903,7 @@ **/ DcmFloatingPointDouble& e = dynamic_cast(element); - if (e.getFloat64Array(content_).good() && - content_ != NULL) + if (e.getFloat64Array(content_).good()) { if (element.getLength() % sizeof(Float64) != 0) { @@ -899,6 +911,12 @@ } size_ = static_cast(element.getLength()) / sizeof(Float64); + if (size_ != 0 && + content_ == NULL) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + valid_ = true; } } @@ -918,6 +936,7 @@ uint64_t index) const ORTHANC_OVERRIDE { assert(valid_); + assert(index < size_); value = boost::lexical_cast(content_[index]); } @@ -953,8 +972,7 @@ { DcmOtherByteOtherWord& e = dynamic_cast(element); - if (e.getUint16Array(content_).good() && - content_ != NULL) + if (e.getUint16Array(content_).good()) { if (element.getLength() % sizeof(Uint16) != 0) { @@ -962,6 +980,12 @@ } size_ = static_cast(element.getLength()) / sizeof(Uint16); + if (size_ != 0 && + content_ == NULL) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + valid_ = true; } } @@ -981,6 +1005,7 @@ uint64_t index) const ORTHANC_OVERRIDE { assert(valid_); + assert(index < size_); value = boost::lexical_cast(content_[index]); } @@ -1022,8 +1047,7 @@ **/ DcmUnsignedLong& e = dynamic_cast(element); - if (e.getUint32Array(content_).good() && - content_ != NULL) + if (e.getUint32Array(content_).good()) { if (element.getLength() % sizeof(Uint32) != 0) { @@ -1031,6 +1055,12 @@ } size_ = static_cast(element.getLength()) / sizeof(Uint32); + if (size_ != 0 && + content_ == NULL) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + valid_ = true; } } @@ -1050,6 +1080,7 @@ uint64_t index) const ORTHANC_OVERRIDE { assert(valid_); + assert(index < size_); value = boost::lexical_cast(content_[index]); } @@ -1086,8 +1117,7 @@ { DcmUnsigned64bitVeryLong& e = dynamic_cast(element); - if (e.getUint64Array(content_).good() && - content_ != NULL) + if (e.getUint64Array(content_).good()) { if (element.getLength() % sizeof(Uint64) != 0) { @@ -1095,6 +1125,12 @@ } size_ = static_cast(element.getLength()) / sizeof(Uint64); + if (size_ != 0 && + content_ == NULL) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + valid_ = true; } } @@ -1114,6 +1150,7 @@ uint64_t index) const ORTHANC_OVERRIDE { assert(valid_); + assert(index < size_); value = boost::lexical_cast(content_[index]); }