From 6eace187e7b9fc7d25e3d67e14b8e432b29f4a23 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Tue, 22 Aug 2023 00:37:45 +0200 Subject: [PATCH] src: add a famous quote --- src/conf.h | 3 +++ src/util/membuffer.cpp | 1 + src/util/util.cpp | 3 +++ 3 files changed, 7 insertions(+) diff --git a/src/conf.h b/src/conf.h index 266f585b..f693ead9 100644 --- a/src/conf.h +++ b/src/conf.h @@ -108,6 +108,9 @@ inline constexpr bool upx_is_integral_v = upx_is_integral::value; // protect against integer overflows and malicious header fields // see C 11 standard, Annex K +// +// this limits uncompressed_size to about 640 MiB which is perfectly fine: +// "640 MiB Ought to be Enough for Anyone" --Markus F.X.J. Oberhumer, 1981 ;-) typedef size_t upx_rsize_t; #define UPX_RSIZE_MAX UPX_RSIZE_MAX_MEM #define UPX_RSIZE_MAX_MEM (768 * 1024 * 1024) // DO NOT CHANGE !!! diff --git a/src/util/membuffer.cpp b/src/util/membuffer.cpp index 6ea80a89..f5398082 100644 --- a/src/util/membuffer.cpp +++ b/src/util/membuffer.cpp @@ -321,6 +321,7 @@ TEST_CASE("MemBuffer::getSizeForCompression") { CHECK(MemBuffer::getSizeForCompression(1024 * 1024) == 1180160); // 0x00100000 CHECK(MemBuffer::getSizeForCompression(64 * 1024 * 1024) == 75497984); // 0x04000000 CHECK(MemBuffer::getSizeForCompression(512 * 1024 * 1024) == 603980288); // 0x20000000 + // "640 MiB Ought to be Enough for Anyone" --Markus F.X.J. Oberhumer, 1981 ;-) CHECK(MemBuffer::getSizeForCompression(640 * 1024 * 1024) == 754975232); // 0x28000000 } diff --git a/src/util/util.cpp b/src/util/util.cpp index bb737715..e241a41e 100644 --- a/src/util/util.cpp +++ b/src/util/util.cpp @@ -42,6 +42,9 @@ // assert sane memory buffer sizes to protect against integer overflows // and malicious header fields // see C 11 standard, Annex K +// +// this limits uncompressed_size to about 640 MiB which is perfectly fine: +// "640 MiB Ought to be Enough for Anyone" --Markus F.X.J. Oberhumer, 1981 ;-) **************************************************************************/ ACC_COMPILE_TIME_ASSERT_HEADER(UPX_RSIZE_MAX_MEM == UPX_RSIZE_MAX)