Mercurial > hg > orthanc
changeset 6684:3289021b83db
fix startup on 32bit architectures
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Sun, 12 Apr 2026 13:33:53 +0200 |
| parents | 765f1ac2baf1 |
| children | 0e54f5c3f43b |
| files | OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp OrthancFramework/Sources/HttpServer/HttpServer.cpp OrthancFramework/Sources/Images/PamReader.cpp OrthancFramework/Sources/Toolbox.cpp OrthancFramework/Sources/Toolbox.h OrthancFramework/UnitTestsSources/ToolboxTests.cpp OrthancServer/Sources/main.cpp |
| diffstat | 7 files changed, 54 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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 <stdio.h> #include <memory> -static const uint64_t MAX_FRAME_SIZE = (static_cast<uint64_t>(std::numeric_limits<size_t>::max()) == 0xFFFFFFFFu - ? static_cast<uint64_t>(1) * 1024 * 1024 * 1024 // 1 GB on 32 bits system - : static_cast<uint64_t>(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
--- 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 <boost/lexical_cast.hpp> #include <boost/thread.hpp> #include <iostream> +#include <limits> #include <stdio.h> #include <string.h>
--- 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 <boost/lexical_cast.hpp> #include <limits> -static const uint64_t MAX_PAM_IMAGE_BUFFER_SIZE = (static_cast<uint64_t>(std::numeric_limits<size_t>::max()) == 0xFFFFFFFFu - ? static_cast<uint64_t>(1) * 1024 * 1024 * 1024 // 1 GB on 32 bits system - : static_cast<uint64_t>(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
--- 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 <json/reader.h> #include <json/version.h> #include <json/writer.h> +#include <limits> #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<size_t>::max()) + { + return std::numeric_limits<size_t>::max(); + } + else if (static_cast<uint64_t>(static_cast<size_t>(size)) == size) + { + return size; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory); + } + } + + Toolbox::ElapsedTimer::ElapsedTimer() { Restart();
--- 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:
--- 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); + } +}
--- 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<uint64_t>(maxBodySize) * - static_cast<uint64_t>(1024 * 1024)); + const uint64_t size = Toolbox::BoundMemorySizeToCurrentArchitecture(static_cast<uint64_t>(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<uint64_t>(maxSizeInArchive) * - static_cast<uint64_t>(1024 * 1024)); - GzipCompressor::SetMaximumUncompressedFileSize(static_cast<uint64_t>(maxSizeInArchive) * - static_cast<uint64_t>(1024 * 1024)); + const uint64_t size = Toolbox::BoundMemorySizeToCurrentArchitecture(static_cast<uint64_t>(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 {
