changeset 6648:dbc3ab1ce86a machine-spirits

fix possible overflow
author Alain Mazy <am@orthanc.team>
date Wed, 04 Mar 2026 11:42:48 +0100
parents 983a74f5b875
children cc45eb4c1371
files OrthancFramework/Sources/DicomFormat/DicomIntegerPixelAccessor.cpp OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp OrthancServer/Sources/ServerContext.cpp
diffstat 3 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomFormat/DicomIntegerPixelAccessor.cpp	Tue Mar 03 16:37:24 2026 +0100
+++ b/OrthancFramework/Sources/DicomFormat/DicomIntegerPixelAccessor.cpp	Wed Mar 04 11:42:48 2026 +0100
@@ -49,7 +49,7 @@
         information_.GetBitsStored() >= 32)
     {
       // Not available, as the accessor internally uses int32_t values
-      throw OrthancException(ErrorCode_NotImplemented);
+      throw OrthancException(ErrorCode_NotImplemented, "No support for BitsAllocated > 32 or BitsStored >= 32");
     }
 
     frame_ = 0;
@@ -57,7 +57,7 @@
 
     if (information_.GetNumberOfFrames() * frameOffset_ > size)
     {
-      throw OrthancException(ErrorCode_BadFileFormat);
+      throw OrthancException(ErrorCode_BadFileFormat, "Invalid size");
     }
 
     if (information_.IsSigned())
--- a/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Tue Mar 03 16:37:24 2026 +0100
+++ b/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Wed Mar 04 11:42:48 2026 +0100
@@ -460,6 +460,13 @@
           throw OrthancException(ErrorCode_NotImplemented, std::string("Palette Color Lookup Table Descriptor invalid palette size: '") + r.c_str() + "'");
         }
 
+        uint64_t expectedSize = static_cast<uint64_t>(target->GetWidth()) * target->GetHeight();
+        
+        if (static_cast<uint64_t>(pixelLength) != expectedSize)
+        {
+          throw OrthancException(ErrorCode_BadFileFormat, "Invalid size");
+        }
+
         if (pixelLength != target->GetWidth() * target->GetHeight())
         {
           DcmElement *elem;
--- a/OrthancServer/Sources/ServerContext.cpp	Tue Mar 03 16:37:24 2026 +0100
+++ b/OrthancServer/Sources/ServerContext.cpp	Wed Mar 04 11:42:48 2026 +0100
@@ -1950,7 +1950,7 @@
       }
       catch (OrthancException& e)
       {
-        LOG(INFO) << e.GetDetails();
+        LOG(INFO) << "Failed to decode a DICOM frame: " << e.GetDetails();
       }
     }