fix(platform): correct wallet-size reporting for files over 2 GiB (Windows)
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<uint64_t>(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<uint64_t>(sz);
|
||||
}
|
||||
|
||||
std::string Platform::formatFileSize(uint64_t bytes)
|
||||
|
||||
Reference in New Issue
Block a user