changeset 6859:8d72870bbfa1

check that the target image has a valid/reasonable size before transcoding to avoid possible crash or OOB during transcoding
author Alain Mazy <am@orthanc.team>
date Tue, 26 May 2026 11:25:25 +0200
parents 4176eb41cf29
children 51fcff053afe
files OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp OrthancFramework/Sources/DicomFormat/DicomImageInformation.h OrthancServer/Sources/ServerContext.cpp
diffstat 3 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp	Thu May 21 14:45:25 2026 +0200
+++ b/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp	Tue May 26 11:25:25 2026 +0200
@@ -503,6 +503,11 @@
   }
 
 
+  void DicomImageInformation::ThrowIfInvalidFrameSize() const
+  {
+    GetFrameSize(); // GetFrameSize() will throw if the image dimensions are too large
+  }
+
   unsigned int DicomImageInformation::GetUsefulTagLength()
   {
     return 256;
--- a/OrthancFramework/Sources/DicomFormat/DicomImageInformation.h	Thu May 21 14:45:25 2026 +0200
+++ b/OrthancFramework/Sources/DicomFormat/DicomImageInformation.h	Tue May 26 11:25:25 2026 +0200
@@ -92,6 +92,8 @@
 
     size_t GetFrameSize() const;
 
+    void ThrowIfInvalidFrameSize() const;
+
     /**
      * This constant gives a bound on the maximum tag length that is
      * useful to class "DicomImageInformation", in order to avoid
--- a/OrthancServer/Sources/ServerContext.cpp	Thu May 21 14:45:25 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Tue May 26 11:25:25 2026 +0200
@@ -26,6 +26,7 @@
 
 #include "../../OrthancFramework/Sources/Cache/SharedArchive.h"
 #include "../../OrthancFramework/Sources/DicomFormat/DicomElement.h"
+#include "../../OrthancFramework/Sources/DicomFormat/DicomImageInformation.h"
 #include "../../OrthancFramework/Sources/DicomFormat/DicomStreamReader.h"
 #include "../../OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.h"
 #include "../../OrthancFramework/Sources/DicomParsing/DicomModification.h"
@@ -1064,6 +1065,15 @@
         
         IDicomTranscoder::DicomImage transcoded;
         
+        if (dicom->HasPixelData())
+        {// check that the target image has a valid/reasonable size before transcoding to avoid possible crash or OOB during transcoding
+          DicomMap summary;
+          dicom->GetSummary(summary);
+
+          DicomImageInformation imageInfo(summary);
+          imageInfo.ThrowIfInvalidFrameSize();
+        }
+
         if (GetTranscoder().Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew /* allow new SOP instance UID */))
         {
           std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile());