changeset 6926:ca0001e90b36

defined global constant MAX_IMAGE_FRAME_SIZE
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 05 Jun 2026 14:28:33 +0200
parents 54c24f421d23
children 57fa3469609a
files OrthancFramework/Sources/Constants.h OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp OrthancFramework/Sources/Images/JpegReader.cpp OrthancFramework/Sources/Images/PamReader.cpp OrthancFramework/Sources/Images/PngReader.cpp
diffstat 7 files changed, 20 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/Constants.h	Fri Jun 05 11:35:15 2026 +0200
+++ b/OrthancFramework/Sources/Constants.h	Fri Jun 05 14:28:33 2026 +0200
@@ -32,4 +32,8 @@
   static const uint64_t KILOBYTE = 1024ull;
   static const uint64_t MEGABYTE = 1024ull * 1024ull;
   static const uint64_t GIGABYTE = 1024ull * 1024ull * 1024ull;
+
+  static const uint64_t MAX_IMAGE_FRAME_SIZE = (sizeof(void*) == 4
+                                                ? 1 * Orthanc::GIGABYTE   // 1 GB on 32 bits system
+                                                : 4 * Orthanc::GIGABYTE); // 4 GB on 64 bits system
 }
--- a/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp	Fri Jun 05 11:35:15 2026 +0200
+++ b/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp	Fri Jun 05 14:28:33 2026 +0200
@@ -43,10 +43,6 @@
 #include <stdio.h>
 #include <memory>
 
-static const uint64_t MAX_FRAME_SIZE = (sizeof(void*) == 4
-                                        ? 1 * Orthanc::GIGABYTE   // 1 GB on 32 bits system
-                                        : 4 * Orthanc::GIGABYTE); // 4 GB on 64 bits system
-
 
 namespace Orthanc
 {
@@ -489,11 +485,11 @@
                         static_cast<uint64_t>(GetChannelCount()));
     }
 
-    if (totalFrameSize > MAX_FRAME_SIZE ||
+    if (totalFrameSize > MAX_IMAGE_FRAME_SIZE ||
         static_cast<uint64_t>(static_cast<size_t>(totalFrameSize)) != totalFrameSize)
     {
       std::ostringstream errorMessage;
-      errorMessage << "DICOM Frame size overflow  (" << totalFrameSize << " vs " << MAX_FRAME_SIZE << ")";
+      errorMessage << "DICOM Frame size overflow  (" << totalFrameSize << " vs. " << MAX_IMAGE_FRAME_SIZE << ")";
       throw OrthancException(ErrorCode_BadFileFormat, errorMessage.str());
     }
     else
--- a/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Fri Jun 05 11:35:15 2026 +0200
+++ b/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Fri Jun 05 14:28:33 2026 +0200
@@ -124,10 +124,6 @@
 #  define EXS_JPEGProcess14SV1  EXS_JPEGProcess14SV1TransferSyntax
 #endif
 
-static const uint64_t MAX_DECODED_FRAME_SIZE = (sizeof(void*) == 4
-                                                ? 1 * Orthanc::GIGABYTE   // 1 GB on 32 bits system
-                                                : 4 * Orthanc::GIGABYTE); // 4 GB on 64 bits system
-
 
 namespace Orthanc
 {
@@ -620,11 +616,11 @@
       {
         uint64_t frameSize = static_cast<uint64_t>(info.GetHeight()) * info.GetWidth() * GetBytesPerPixel(sourceFormat);
 
-        if (frameSize > MAX_DECODED_FRAME_SIZE ||
+        if (frameSize > MAX_IMAGE_FRAME_SIZE ||
             static_cast<uint64_t>(static_cast<size_t>(frameSize)) != frameSize)
         {
           std::ostringstream errorMessage;
-          errorMessage << "ImageDecoder: max decoded frame size overflow  (" << frameSize << " vs " << MAX_DECODED_FRAME_SIZE << ")";
+          errorMessage << "ImageDecoder: max decoded frame size overflow  (" << frameSize << " vs. " << MAX_IMAGE_FRAME_SIZE << ")";
           throw OrthancException(ErrorCode_BadFileFormat, errorMessage.str());
         }
 
@@ -784,17 +780,17 @@
       std::string uncompressed;
       uint64_t frameSize = static_cast<uint64_t>(info.GetWidth()) * info.GetHeight() * info.GetBytesPerValue();
 
-      if (frameSize > MAX_DECODED_FRAME_SIZE ||
+      if (frameSize > MAX_IMAGE_FRAME_SIZE ||
           static_cast<uint64_t>(static_cast<size_t>(frameSize)) != frameSize)
       {
         std::ostringstream errorMessage;
-        errorMessage << "ImageDecoder: max decoded frame size overflow  (" << frameSize << " vs " << MAX_DECODED_FRAME_SIZE << ")";
+        errorMessage << "ImageDecoder: max decoded frame size overflow  (" << frameSize << " vs. " << MAX_IMAGE_FRAME_SIZE << ")";
         throw OrthancException(ErrorCode_BadFileFormat, errorMessage.str());
       }
 
       uncompressed.resize(frameSize);
 
-      if (static_cast<uint64_t>(static_cast<Uint32>(frameSize)) != frameSize) // in case, some day, MAX_DECODED_FRAME_SIZE gets larger than 4GB
+      if (static_cast<uint64_t>(static_cast<Uint32>(frameSize)) != frameSize) // in case, some day, MAX_IMAGE_FRAME_SIZE gets larger than 4GB
       {
         std::ostringstream errorMessage;
         errorMessage << "ImageDecoder: frameSize too large for DCMTK interface (" << frameSize << ")";
--- a/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp	Fri Jun 05 11:35:15 2026 +0200
+++ b/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp	Fri Jun 05 14:28:33 2026 +0200
@@ -147,10 +147,6 @@
 #  define EXS_JPEGProcess1      EXS_JPEGProcess1TransferSyntax
 #endif
 
-static const uint64_t MAX_OVERLAY_SIZE = (sizeof(void*) == 4
-                                          ? 1 * Orthanc::GIGABYTE   // 1 GB on 32 bits system
-                                          : 4 * Orthanc::GIGABYTE); // 4 GB on 64 bits system
-
 
 namespace Orthanc
 {
@@ -2137,15 +2133,15 @@
 
       uint64_t expectedOverlaySize = Ceiling(static_cast<uint64_t>(rows) * columns, 8);
 
-      if (expectedOverlaySize > MAX_OVERLAY_SIZE ||
+      if (expectedOverlaySize > MAX_IMAGE_FRAME_SIZE ||
           static_cast<uint64_t>(static_cast<size_t>(expectedOverlaySize)) != expectedOverlaySize)
       {
         std::ostringstream errorMessage;
-        errorMessage << "ParsedDicomFile: max overlay size overflow  (" << expectedOverlaySize << " vs " << MAX_OVERLAY_SIZE << ")";
+        errorMessage << "ParsedDicomFile: max overlay size overflow  (" << expectedOverlaySize << " vs. " << MAX_IMAGE_FRAME_SIZE << ")";
         throw OrthancException(ErrorCode_BadFileFormat, errorMessage.str());
       }
 
-      if (static_cast<uint64_t>(static_cast<Uint32>(expectedOverlaySize)) != expectedOverlaySize) // in case, some day, MAX_OVERLAY_SIZE gets larger than 4GB
+      if (static_cast<uint64_t>(static_cast<Uint32>(expectedOverlaySize)) != expectedOverlaySize) // in case, some day, MAX_IMAGE_FRAME_SIZE gets larger than 4GB
       {
         std::ostringstream errorMessage;
         errorMessage << "ParsedDicomFile: expectedOverlaySize too large for DCMTK interface (" << expectedOverlaySize << ")";
--- a/OrthancFramework/Sources/Images/JpegReader.cpp	Fri Jun 05 11:35:15 2026 +0200
+++ b/OrthancFramework/Sources/Images/JpegReader.cpp	Fri Jun 05 14:28:33 2026 +0200
@@ -34,9 +34,6 @@
 #  include "../SystemToolbox.h"
 #endif
 
-static const uint64_t MAX_DECODED_JPEG_IMAGE_SIZE = (sizeof(void*) == 4
-                                                     ? 1 * Orthanc::GIGABYTE   // 1 GB on 32 bits system
-                                                     : 4 * Orthanc::GIGABYTE); // 4 GB on 64 bits system
 
 namespace Orthanc
 {
@@ -69,11 +66,11 @@
     uint64_t pitch = static_cast<uint64_t>(cinfo.output_width) * cinfo.output_components;
     uint64_t totalSize = pitch * cinfo.output_height;
 
-    if (totalSize > MAX_DECODED_JPEG_IMAGE_SIZE ||
+    if (totalSize > MAX_IMAGE_FRAME_SIZE ||
         static_cast<uint64_t>(static_cast<size_t>(totalSize)) != totalSize)
     {
       std::ostringstream errorMessage;
-      errorMessage << "JPEG IMAGE size overflow  (" << totalSize << " vs " << MAX_DECODED_JPEG_IMAGE_SIZE << ")";
+      errorMessage << "JPEG IMAGE size overflow  (" << totalSize << " vs. " << MAX_IMAGE_FRAME_SIZE << ")";
       throw OrthancException(ErrorCode_BadFileFormat, errorMessage.str());
     }
 
--- a/OrthancFramework/Sources/Images/PamReader.cpp	Fri Jun 05 11:35:15 2026 +0200
+++ b/OrthancFramework/Sources/Images/PamReader.cpp	Fri Jun 05 14:28:33 2026 +0200
@@ -40,10 +40,6 @@
 #include <boost/lexical_cast.hpp>
 #include <limits>
 
-static const uint64_t MAX_PAM_IMAGE_BUFFER_SIZE = (sizeof(void*) == 4
-                                                   ? 1 * Orthanc::GIGABYTE   // 1 GB on 32 bits system
-                                                   : 4 * Orthanc::GIGABYTE); // 4 GB on 64 bits system
-
 
 namespace Orthanc
 {
@@ -204,11 +200,11 @@
     }
 
     uint64_t totalSize = pitch * height;
-    if (totalSize > MAX_PAM_IMAGE_BUFFER_SIZE ||
+    if (totalSize > MAX_IMAGE_FRAME_SIZE ||
         static_cast<uint64_t>(static_cast<size_t>(totalSize)) != totalSize)
     {
       std::ostringstream errorMessage;
-      errorMessage << "PAM image too large  (" << totalSize << " vs " << MAX_PAM_IMAGE_BUFFER_SIZE << ")";
+      errorMessage << "PAM image too large  (" << totalSize << " vs. " << MAX_IMAGE_FRAME_SIZE << ")";
       throw OrthancException(ErrorCode_BadFileFormat, errorMessage.str());
     }
 
--- a/OrthancFramework/Sources/Images/PngReader.cpp	Fri Jun 05 11:35:15 2026 +0200
+++ b/OrthancFramework/Sources/Images/PngReader.cpp	Fri Jun 05 14:28:33 2026 +0200
@@ -39,11 +39,6 @@
 #include <sstream>
 
 
-static const uint64_t MAX_DECODED_PNG_IMAGE_SIZE = (sizeof(void*) == 4
-                                                    ? 1 * Orthanc::GIGABYTE   // 1 GB on 32 bits system
-                                                    : 4 * Orthanc::GIGABYTE); // 4 GB on 64 bits system
-
-
 namespace Orthanc
 {
 #if ORTHANC_SANDBOXED == 0
@@ -201,11 +196,11 @@
     }
 
     uint64_t totalSize = pitch * height;
-    if (totalSize > MAX_DECODED_PNG_IMAGE_SIZE ||
+    if (totalSize > MAX_IMAGE_FRAME_SIZE ||
         static_cast<uint64_t>(static_cast<size_t>(totalSize)) != totalSize)
     {
       std::ostringstream errorMessage;
-      errorMessage << "PNG IMAGE size overflow  (" << totalSize << " vs " << MAX_DECODED_PNG_IMAGE_SIZE << ")";
+      errorMessage << "PNG IMAGE size overflow  (" << totalSize << " vs. " << MAX_IMAGE_FRAME_SIZE << ")";
       throw OrthancException(ErrorCode_BadFileFormat, errorMessage.str());
     }