# HG changeset patch # User Sebastien Jodogne # Date 1773995536 -3600 # Node ID b8e78ccac53255281d385cdc34f661acb67dd186 # Parent dfa66ab964c9fe6aad44d6f6cbba61382c63c5a9 added safeguards diff -r dfa66ab964c9 -r b8e78ccac532 OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp --- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp Fri Mar 20 09:28:18 2026 +0100 +++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp Fri Mar 20 09:32:16 2026 +0100 @@ -888,6 +888,11 @@ Float32* floatArray = NULL; if (content.getFloat32Array(floatArray).good() && floatArray != NULL) { + if (element.getLength() % sizeof(Float32) != 0) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + const unsigned long numFloats = element.getLength() / sizeof(Float32); std::string result; for (unsigned long i = 0; i < numFloats; i++) @@ -916,6 +921,11 @@ Float64* doubleArray = NULL; if (content.getFloat64Array(doubleArray).good() && doubleArray != NULL) { + if (element.getLength() % sizeof(Float64) != 0) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + const unsigned long numDoubles = element.getLength() / sizeof(Float64); std::string result; for (unsigned long i = 0; i < numDoubles; i++) @@ -945,6 +955,11 @@ Uint32* uint32Array = NULL; if (content.getUint32Array(uint32Array).good() && uint32Array != NULL) { + if (element.getLength() % sizeof(Uint32) != 0) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + const unsigned long numValues = element.getLength() / sizeof(Uint32); std::string result; for (unsigned long i = 0; i < numValues; i++) @@ -3175,6 +3190,11 @@ Float32* floatArray = NULL; if (content.getFloat32Array(floatArray).good() && floatArray != NULL) { + if (element.getLength() % sizeof(Float32) != 0) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + const unsigned long numFloats = static_cast(element.getLength() / sizeof(Float32)); values.reserve(numFloats); @@ -3204,6 +3224,11 @@ Float64* doubleArray = NULL; if (content.getFloat64Array(doubleArray).good() && doubleArray != NULL) { + if (element.getLength() % sizeof(Float64) != 0) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + const unsigned long numDoubles = static_cast(element.getLength() / sizeof(Float64)); values.reserve(numDoubles); @@ -3234,6 +3259,11 @@ Uint32* uint32Array = NULL; if (content.getUint32Array(uint32Array).good() && uint32Array != NULL) { + if (element.getLength() % sizeof(Uint32) != 0) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + const unsigned long numValues = static_cast(element.getLength() / sizeof(Uint32)); values.reserve(numValues);