From 743d160fdd12d2e30ff8a0cead90346b9d226b97 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 30 Jul 2025 18:40:25 +0100 Subject: [PATCH] about: fix potential overflow of about in various backends Before this fix it was possible for an about call in various backends to exceed an int64 and wrap. This patch causes it to clip to the max int64 value instead. --- backend/dropbox/dropbox.go | 6 +++--- backend/hdfs/fs.go | 6 +++--- backend/mega/mega.go | 6 +++--- backend/premiumizeme/premiumizeme.go | 2 +- backend/sftp/sftp.go | 6 +++--- backend/smb/smb.go | 8 ++++---- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/backend/dropbox/dropbox.go b/backend/dropbox/dropbox.go index 661bc8241..f67a9e261 100644 --- a/backend/dropbox/dropbox.go +++ b/backend/dropbox/dropbox.go @@ -1446,9 +1446,9 @@ func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) { } } usage = &fs.Usage{ - Total: fs.NewUsageValue(int64(total)), // quota of bytes that can be used - Used: fs.NewUsageValue(int64(used)), // bytes in use - Free: fs.NewUsageValue(int64(total - used)), // bytes which can be uploaded before reaching the quota + Total: fs.NewUsageValue(total), // quota of bytes that can be used + Used: fs.NewUsageValue(used), // bytes in use + Free: fs.NewUsageValue(total - used), // bytes which can be uploaded before reaching the quota } return usage, nil } diff --git a/backend/hdfs/fs.go b/backend/hdfs/fs.go index 7a309d608..f6e306053 100644 --- a/backend/hdfs/fs.go +++ b/backend/hdfs/fs.go @@ -371,9 +371,9 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) { return nil, err } return &fs.Usage{ - Total: fs.NewUsageValue(int64(info.Capacity)), - Used: fs.NewUsageValue(int64(info.Used)), - Free: fs.NewUsageValue(int64(info.Remaining)), + Total: fs.NewUsageValue(info.Capacity), + Used: fs.NewUsageValue(info.Used), + Free: fs.NewUsageValue(info.Remaining), }, nil } diff --git a/backend/mega/mega.go b/backend/mega/mega.go index 175fc643e..eec71f556 100644 --- a/backend/mega/mega.go +++ b/backend/mega/mega.go @@ -946,9 +946,9 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) { return nil, fmt.Errorf("failed to get Mega Quota: %w", err) } usage := &fs.Usage{ - Total: fs.NewUsageValue(int64(q.Mstrg)), // quota of bytes that can be used - Used: fs.NewUsageValue(int64(q.Cstrg)), // bytes in use - Free: fs.NewUsageValue(int64(q.Mstrg - q.Cstrg)), // bytes which can be uploaded before reaching the quota + Total: fs.NewUsageValue(q.Mstrg), // quota of bytes that can be used + Used: fs.NewUsageValue(q.Cstrg), // bytes in use + Free: fs.NewUsageValue(q.Mstrg - q.Cstrg), // bytes which can be uploaded before reaching the quota } return usage, nil } diff --git a/backend/premiumizeme/premiumizeme.go b/backend/premiumizeme/premiumizeme.go index 5bf87badf..3991d19ee 100644 --- a/backend/premiumizeme/premiumizeme.go +++ b/backend/premiumizeme/premiumizeme.go @@ -793,7 +793,7 @@ func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) { return nil, err } usage = &fs.Usage{ - Used: fs.NewUsageValue(int64(info.SpaceUsed)), + Used: fs.NewUsageValue(info.SpaceUsed), } return usage, nil } diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go index fd5819217..e3d5242fb 100644 --- a/backend/sftp/sftp.go +++ b/backend/sftp/sftp.go @@ -1863,9 +1863,9 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) { free := vfsStats.FreeSpace() used := total - free return &fs.Usage{ - Total: fs.NewUsageValue(int64(total)), - Used: fs.NewUsageValue(int64(used)), - Free: fs.NewUsageValue(int64(free)), + Total: fs.NewUsageValue(total), + Used: fs.NewUsageValue(used), + Free: fs.NewUsageValue(free), }, nil } else if err != nil { if errors.Is(err, os.ErrNotExist) { diff --git a/backend/smb/smb.go b/backend/smb/smb.go index 7e53a39db..d102233f5 100644 --- a/backend/smb/smb.go +++ b/backend/smb/smb.go @@ -494,11 +494,11 @@ func (f *Fs) About(ctx context.Context) (_ *fs.Usage, err error) { return nil, err } - bs := int64(stat.BlockSize()) + bs := stat.BlockSize() usage := &fs.Usage{ - Total: fs.NewUsageValue(bs * int64(stat.TotalBlockCount())), - Used: fs.NewUsageValue(bs * int64(stat.TotalBlockCount()-stat.FreeBlockCount())), - Free: fs.NewUsageValue(bs * int64(stat.AvailableBlockCount())), + Total: fs.NewUsageValue(bs * stat.TotalBlockCount()), + Used: fs.NewUsageValue(bs * (stat.TotalBlockCount() - stat.FreeBlockCount())), + Free: fs.NewUsageValue(bs * stat.AvailableBlockCount()), } return usage, nil }