Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

about: fix potential overflow of about in various backends

Nick Craig-Wood743d160fdd12
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
}