# HG changeset patch # User Sebastien Jodogne # Date 1775993633 -7200 # Node ID 3289021b83db45be92744ccc1c98aaa0b6d19f6b # Parent 765f1ac2baf1818cc886fba52dfa0f934f031996 fix startup on 32bit architectures diff -r 765f1ac2baf1 -r 3289021b83db OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp --- a/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp Fri Apr 10 17:03:17 2026 +0200 +++ b/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp Sun Apr 12 13:33:53 2026 +0200 @@ -42,9 +42,9 @@ #include #include -static const uint64_t MAX_FRAME_SIZE = (static_cast(std::numeric_limits::max()) == 0xFFFFFFFFu - ? static_cast(1) * 1024 * 1024 * 1024 // 1 GB on 32 bits system - : static_cast(4) * 1024 * 1024 * 1024); // 4 GiB on 64 bits system +static const uint64_t MAX_FRAME_SIZE = (sizeof(void*) == 4 + ? 1llu * 1024llu * 1024llu * 1024llu // 1 GB on 32 bits system + : 4llu * 1024llu * 1024llu * 1024llu); // 4 GB on 64 bits system namespace Orthanc diff -r 765f1ac2baf1 -r 3289021b83db OrthancFramework/Sources/HttpServer/HttpServer.cpp --- a/OrthancFramework/Sources/HttpServer/HttpServer.cpp Fri Apr 10 17:03:17 2026 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpServer.cpp Sun Apr 12 13:33:53 2026 +0200 @@ -66,6 +66,7 @@ #include #include #include +#include #include #include diff -r 765f1ac2baf1 -r 3289021b83db OrthancFramework/Sources/Images/PamReader.cpp --- a/OrthancFramework/Sources/Images/PamReader.cpp Fri Apr 10 17:03:17 2026 +0200 +++ b/OrthancFramework/Sources/Images/PamReader.cpp Sun Apr 12 13:33:53 2026 +0200 @@ -39,10 +39,9 @@ #include #include -static const uint64_t MAX_PAM_IMAGE_BUFFER_SIZE = (static_cast(std::numeric_limits::max()) == 0xFFFFFFFFu - ? static_cast(1) * 1024 * 1024 * 1024 // 1 GB on 32 bits system - : static_cast(4) * 1024 * 1024 * 1024); // 4 GiB on 64 bits system - +static const uint64_t MAX_PAM_IMAGE_BUFFER_SIZE = (sizeof(void*) == 4 + ? 1llu * 1024llu * 1024llu * 1024llu // 1 GB on 32 bits system + : 4llu * 1024llu * 1024llu * 1024llu); // 4 GB on 64 bits system namespace Orthanc diff -r 765f1ac2baf1 -r 3289021b83db OrthancFramework/Sources/Toolbox.cpp --- a/OrthancFramework/Sources/Toolbox.cpp Fri Apr 10 17:03:17 2026 +0200 +++ b/OrthancFramework/Sources/Toolbox.cpp Sun Apr 12 13:33:53 2026 +0200 @@ -32,6 +32,7 @@ #include #include #include +#include #if !defined(JSONCPP_VERSION_MAJOR) || !defined(JSONCPP_VERSION_MINOR) # error Cannot access the version of JsonCpp @@ -3050,6 +3051,24 @@ } + size_t Toolbox::BoundMemorySizeToCurrentArchitecture(uint64_t size) + { + if (sizeof(void*) == 4 && + size > std::numeric_limits::max()) + { + return std::numeric_limits::max(); + } + else if (static_cast(static_cast(size)) == size) + { + return size; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory); + } + } + + Toolbox::ElapsedTimer::ElapsedTimer() { Restart(); diff -r 765f1ac2baf1 -r 3289021b83db OrthancFramework/Sources/Toolbox.h --- a/OrthancFramework/Sources/Toolbox.h Fri Apr 10 17:03:17 2026 +0200 +++ b/OrthancFramework/Sources/Toolbox.h Sun Apr 12 13:33:53 2026 +0200 @@ -413,6 +413,8 @@ bool allowUtf8, bool allowSlashes); + static size_t BoundMemorySizeToCurrentArchitecture(uint64_t size); + class ORTHANC_PUBLIC ElapsedTimer : public boost::noncopyable { private: diff -r 765f1ac2baf1 -r 3289021b83db OrthancFramework/UnitTestsSources/ToolboxTests.cpp --- a/OrthancFramework/UnitTestsSources/ToolboxTests.cpp Fri Apr 10 17:03:17 2026 +0200 +++ b/OrthancFramework/UnitTestsSources/ToolboxTests.cpp Sun Apr 12 13:33:53 2026 +0200 @@ -459,3 +459,21 @@ ASSERT_FALSE(Orthanc::Toolbox::IsValidUtf8("\xFF")); // Invalid leading byte ASSERT_FALSE(Orthanc::Toolbox::IsValidUtf8("\xF0\x28\x8C\x28")); } + +TEST(Toolbox, BoundMemorySizeToCurrentArchitecture) +{ + if (sizeof(void*) == 4) + { + ASSERT_EQ(Toolbox::BoundMemorySizeToCurrentArchitecture(4294967295llu), 4294967295llu); + ASSERT_EQ(Toolbox::BoundMemorySizeToCurrentArchitecture(4294967296llu), 4294967295llu); + } + else if (sizeof(void*) == 8) + { + ASSERT_EQ(Toolbox::BoundMemorySizeToCurrentArchitecture(4294967295llu), 4294967295llu); + ASSERT_EQ(Toolbox::BoundMemorySizeToCurrentArchitecture(4294967296llu), 4294967296llu); + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); + } +} diff -r 765f1ac2baf1 -r 3289021b83db OrthancServer/Sources/main.cpp --- a/OrthancServer/Sources/main.cpp Fri Apr 10 17:03:17 2026 +0200 +++ b/OrthancServer/Sources/main.cpp Sun Apr 12 13:33:53 2026 +0200 @@ -1129,12 +1129,13 @@ httpServer.SetRequestTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("HttpRequestTimeout", 30)); // New in Orthanc 1.12.11 + static const uint64_t MEGABYTE = 1024llu * 1024llu; const unsigned int maxBodySize = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumRequestBodySizeMB", 8192); if (maxBodySize != 0) { - LOG(WARNING) << "Limiting the maximum body size in HTTP requests to " << maxBodySize << "MB"; - httpServer.SetMaxBodySize(static_cast(maxBodySize) * - static_cast(1024 * 1024)); + const uint64_t size = Toolbox::BoundMemorySizeToCurrentArchitecture(static_cast(maxBodySize) * MEGABYTE); + LOG(WARNING) << "Limiting the maximum body size in HTTP requests to " << (size / MEGABYTE) << "MB"; + httpServer.SetMaxBodySize(size); } else { @@ -1144,11 +1145,10 @@ const unsigned int maxSizeInArchive = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumFileSizeInArchiveMB", 4096); if (maxSizeInArchive != 0) { - LOG(WARNING) << "Limiting on the maximum file size uncompressed from ZIP/gzip archives to " << maxSizeInArchive << "MB"; - ZipReader::SetMaximumUncompressedFileSize(static_cast(maxSizeInArchive) * - static_cast(1024 * 1024)); - GzipCompressor::SetMaximumUncompressedFileSize(static_cast(maxSizeInArchive) * - static_cast(1024 * 1024)); + const uint64_t size = Toolbox::BoundMemorySizeToCurrentArchitecture(static_cast(maxSizeInArchive) * MEGABYTE); + LOG(WARNING) << "Limiting on the maximum file size uncompressed from ZIP/gzip archives to " << (size / MEGABYTE) << "MB"; + ZipReader::SetMaximumUncompressedFileSize(size); + GzipCompressor::SetMaximumUncompressedFileSize(size); } else {