changeset 6632:b8e78ccac532

added safeguards
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 20 Mar 2026 09:32:16 +0100
parents dfa66ab964c9
children a0bbb4d460b8 ab12547ac3df f1140bd7ed65
files OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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<unsigned long>(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<unsigned long>(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<unsigned long>(element.getLength() / sizeof(Uint32));
             values.reserve(numValues);