]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
chore: Bail out on too large files on 32-bit systems
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 10 Feb 2024 20:33:08 +0000 (21:33 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 11 Feb 2024 13:19:27 +0000 (14:19 +0100)
src/util/file.cpp

index 5b776297fec3262d6962683a4be0da38cefc17f8..87600422ff2f5d07646f3cfb2c24c3ca0323fa68 100644 (file)
@@ -240,6 +240,12 @@ read_file(const fs::path& path, size_t size_hint)
     size_hint = de.size();
   }
 
+  if (size_hint > std::numeric_limits<size_t>::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<T, std::string>::value) {
       return O_RDONLY | O_TEXT;