diff --git a/src/util/platform.cpp b/src/util/platform.cpp index 2c3c5f0..c471aca 100644 --- a/src/util/platform.cpp +++ b/src/util/platform.cpp @@ -187,11 +187,15 @@ bool Platform::openFolder(const std::string& path, bool createIfMissing) uint64_t Platform::getFileSize(const std::string& path) { - struct stat st; - if (stat(path.c_str(), &st) == 0) { - return static_cast(st.st_size); - } - return 0; + // Use std::filesystem (64-bit uintmax_t) rather than stat(): on mingw/Windows struct stat's + // st_size is a 32-bit signed _off_t, so a wallet.dat over 2 GiB overflows negative and casts to a + // garbage ~2^64 value (the "17179869182 GB" bug). The error_code overload returns on failure + // (missing / unreadable / Windows sharing violation while the daemon holds the file) instead of + // throwing, and we report 0 so callers fall back to "unknown". + std::error_code ec; + const auto sz = std::filesystem::file_size(path, ec); + if (ec) return 0; + return static_cast(sz); } std::string Platform::formatFileSize(uint64_t bytes)