From e4f50ac7c160119ae363c934ef84adad69a68ecf Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sat, 10 Feb 2024 21:33:08 +0100 Subject: [PATCH] chore: Bail out on too large files on 32-bit systems --- src/util/file.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/util/file.cpp b/src/util/file.cpp index 5b776297..87600422 100644 --- a/src/util/file.cpp +++ b/src/util/file.cpp @@ -240,6 +240,12 @@ read_file(const fs::path& path, size_t size_hint) size_hint = de.size(); } + if (size_hint > std::numeric_limits::max() / 4) { + // Too large value on a 32-bit system won't work well, better bail. + return tl::unexpected( + FMT("too large file: {} ({} bytes)", path, size_hint)); + } + const int open_flags = [] { if constexpr (std::is_same::value) { return O_RDONLY | O_TEXT; -- 2.47.2