1
0
mirror of https://github.com/rclone/rclone.git synced 2025-11-23 21:44:49 +02:00

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.
This commit is contained in:
Nick Craig-Wood
2025-07-30 18:40:25 +01:00
parent dc95f36bc1
commit 743d160fdd
6 changed files with 17 additions and 17 deletions

View File

@@ -1446,9 +1446,9 @@ func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) {
} }
} }
usage = &fs.Usage{ usage = &fs.Usage{
Total: fs.NewUsageValue(int64(total)), // quota of bytes that can be used Total: fs.NewUsageValue(total), // quota of bytes that can be used
Used: fs.NewUsageValue(int64(used)), // bytes in use Used: fs.NewUsageValue(used), // bytes in use
Free: fs.NewUsageValue(int64(total - used)), // bytes which can be uploaded before reaching the quota Free: fs.NewUsageValue(total - used), // bytes which can be uploaded before reaching the quota
} }
return usage, nil return usage, nil
} }

View File

@@ -371,9 +371,9 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
return nil, err return nil, err
} }
return &fs.Usage{ return &fs.Usage{
Total: fs.NewUsageValue(int64(info.Capacity)), Total: fs.NewUsageValue(info.Capacity),
Used: fs.NewUsageValue(int64(info.Used)), Used: fs.NewUsageValue(info.Used),
Free: fs.NewUsageValue(int64(info.Remaining)), Free: fs.NewUsageValue(info.Remaining),
}, nil }, nil
} }

View File

@@ -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) return nil, fmt.Errorf("failed to get Mega Quota: %w", err)
} }
usage := &fs.Usage{ usage := &fs.Usage{
Total: fs.NewUsageValue(int64(q.Mstrg)), // quota of bytes that can be used Total: fs.NewUsageValue(q.Mstrg), // quota of bytes that can be used
Used: fs.NewUsageValue(int64(q.Cstrg)), // bytes in use Used: fs.NewUsageValue(q.Cstrg), // bytes in use
Free: fs.NewUsageValue(int64(q.Mstrg - q.Cstrg)), // bytes which can be uploaded before reaching the quota Free: fs.NewUsageValue(q.Mstrg - q.Cstrg), // bytes which can be uploaded before reaching the quota
} }
return usage, nil return usage, nil
} }

View File

@@ -793,7 +793,7 @@ func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) {
return nil, err return nil, err
} }
usage = &fs.Usage{ usage = &fs.Usage{
Used: fs.NewUsageValue(int64(info.SpaceUsed)), Used: fs.NewUsageValue(info.SpaceUsed),
} }
return usage, nil return usage, nil
} }

View File

@@ -1863,9 +1863,9 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
free := vfsStats.FreeSpace() free := vfsStats.FreeSpace()
used := total - free used := total - free
return &fs.Usage{ return &fs.Usage{
Total: fs.NewUsageValue(int64(total)), Total: fs.NewUsageValue(total),
Used: fs.NewUsageValue(int64(used)), Used: fs.NewUsageValue(used),
Free: fs.NewUsageValue(int64(free)), Free: fs.NewUsageValue(free),
}, nil }, nil
} else if err != nil { } else if err != nil {
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {

View File

@@ -494,11 +494,11 @@ func (f *Fs) About(ctx context.Context) (_ *fs.Usage, err error) {
return nil, err return nil, err
} }
bs := int64(stat.BlockSize()) bs := stat.BlockSize()
usage := &fs.Usage{ usage := &fs.Usage{
Total: fs.NewUsageValue(bs * int64(stat.TotalBlockCount())), Total: fs.NewUsageValue(bs * stat.TotalBlockCount()),
Used: fs.NewUsageValue(bs * int64(stat.TotalBlockCount()-stat.FreeBlockCount())), Used: fs.NewUsageValue(bs * (stat.TotalBlockCount() - stat.FreeBlockCount())),
Free: fs.NewUsageValue(bs * int64(stat.AvailableBlockCount())), Free: fs.NewUsageValue(bs * stat.AvailableBlockCount()),
} }
return usage, nil return usage, nil
} }