From 12c61bd796152e76e8c03975cb3ea168381fc29d Mon Sep 17 00:00:00 2001 From: DanS Date: Mon, 26 Oct 2026 11:45:42 -0500 Subject: [PATCH] fix(platform): correct wallet-size reporting for files over 2 GiB (Windows) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getFileSize used stat(), whose st_size is a 32-bit signed _off_t on mingw/ Windows, so a wallet.dat over 2 GiB overflowed negative and cast to a garbage ~2^64 value — the "Wallet Size: 17179869182.10 GB" (≈ 2^34 GiB) seen on a real ~2.1 GB shielded wallet, which also spuriously fired the "wallet is large" banner. Switch to std::filesystem::file_size (portable 64-bit uintmax_t) with the error_code overload, returning 0 on failure (missing / unreadable / a Windows sharing violation while the daemon holds the file open) so the callers' existing `> 0` guards fall back to "unknown". The size now reports correctly, and the large-wallet warning fires on the real size (so a genuinely bloated 2+ GiB wallet is flagged, as intended). Co-Authored-By: Claude Opus 4.8 --- src/util/platform.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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)