Mercurial > hg > orthanc
changeset 6931:9a9203c1fe4c streaming
Prevent creation of too large images at low level (fixes test_oob_monochrome_2 with GDCM in streaming branch)
| author | Alain Mazy <am@orthanc.team> |
|---|---|
| date | Fri, 05 Jun 2026 17:11:07 +0200 |
| parents | ec3781d07f48 |
| children | |
| files | OrthancFramework/Sources/Images/ImageBuffer.cpp |
| diffstat | 1 files changed, 6 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/Images/ImageBuffer.cpp Fri Jun 05 16:53:05 2026 +0200 +++ b/OrthancFramework/Sources/Images/ImageBuffer.cpp Fri Jun 05 17:11:07 2026 +0200 @@ -26,6 +26,7 @@ #include "ImageBuffer.h" #include "../OrthancException.h" +#include "../Constants.h" #include <boost/lexical_cast.hpp> #include <stdio.h> @@ -49,6 +50,11 @@ const uint64_t tmpPitch = static_cast<uint64_t>(GetBytesPerPixel()) * static_cast<uint64_t>(width_); const uint64_t size = tmpPitch * static_cast<uint64_t>(height_); + if (size > MAX_IMAGE_FRAME_SIZE) { + throw OrthancException(ErrorCode_BadFileFormat, std::string("Trying to create an ImageBuffer whose size (") + boost::lexical_cast<std::string>(size) + " bytes) is larger than the limit (" + boost::lexical_cast<std::string>(MAX_IMAGE_FRAME_SIZE) + " bytes)"); + } + + if (static_cast<uint64_t>(static_cast<unsigned int>(tmpPitch)) != tmpPitch || static_cast<uint64_t>(static_cast<size_t>(size)) != size) {
