changeset 5838:4b47151dea4c

fix crashes if handling very large images
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 16 Oct 2024 18:27:31 +0200
parents 37e5d0918006
children 7aef730c0859
files NEWS OrthancFramework/Sources/Images/ImageAccessor.cpp OrthancFramework/Sources/Images/ImageAccessor.h OrthancFramework/Sources/Images/ImageBuffer.cpp
diffstat 4 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Sep 30 10:22:12 2024 +0200
+++ b/NEWS	Wed Oct 16 18:27:31 2024 +0200
@@ -29,6 +29,7 @@
 * Fix C-Find queries not returning private tags in the modality worklist plugin.
 * Fix extremely rare error when 2 threads are trying to create the same folder in the File Storage 
   at the same time.
+* Fix crashes if handling very large images
 * Metrics:
   - fix a few metrics that were not published
   - added 2 metrics: orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count 
--- a/OrthancFramework/Sources/Images/ImageAccessor.cpp	Mon Sep 30 10:22:12 2024 +0200
+++ b/OrthancFramework/Sources/Images/ImageAccessor.cpp	Wed Oct 16 18:27:31 2024 +0200
@@ -139,7 +139,7 @@
     return pitch_;
   }
 
-  unsigned int ImageAccessor::GetSize() const
+  size_t ImageAccessor::GetSize() const
   {
     return GetHeight() * GetPitch();
   }
@@ -165,7 +165,7 @@
   {
     if (buffer_ != NULL)
     {
-      return buffer_ + y * pitch_;
+      return buffer_ + static_cast<size_t>(y) * static_cast<size_t>(pitch_);
     }
     else
     {
@@ -184,7 +184,7 @@
 
     if (buffer_ != NULL)
     {
-      return buffer_ + y * pitch_;
+      return buffer_ + static_cast<size_t>(y) * static_cast<size_t>(pitch_);
     }
     else
     {
@@ -325,8 +325,8 @@
     else
     {
       uint8_t* p = (buffer_ + 
-                    y * pitch_ + 
-                    x * GetBytesPerPixel());
+                    static_cast<size_t>(y) * static_cast<size_t>(pitch_) +
+                    static_cast<size_t>(x) * static_cast<size_t>(GetBytesPerPixel()));
 
       if (readOnly_)
       {
--- a/OrthancFramework/Sources/Images/ImageAccessor.h	Mon Sep 30 10:22:12 2024 +0200
+++ b/OrthancFramework/Sources/Images/ImageAccessor.h	Wed Oct 16 18:27:31 2024 +0200
@@ -86,7 +86,7 @@
 
     unsigned int GetPitch() const;
 
-    unsigned int GetSize() const;
+    size_t GetSize() const;
 
     const void* GetConstBuffer() const;
 
--- a/OrthancFramework/Sources/Images/ImageBuffer.cpp	Mon Sep 30 10:22:12 2024 +0200
+++ b/OrthancFramework/Sources/Images/ImageBuffer.cpp	Wed Oct 16 18:27:31 2024 +0200
@@ -47,7 +47,7 @@
       */
 
       pitch_ = GetBytesPerPixel() * width_;
-      size_t size = pitch_ * height_;
+      size_t size = static_cast<size_t>(pitch_) * static_cast<size_t>(height_);
 
       if (size == 0)
       {