Skip to content

Commit 743d160

Browse files
committed
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.
1 parent dc95f36 commit 743d160

6 files changed

Lines changed: 17 additions & 17 deletions

File tree

backend/dropbox/dropbox.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,9 +1446,9 @@ func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) {
14461446
}
14471447
}
14481448
usage = &fs.Usage{
1449-
Total: fs.NewUsageValue(int64(total)), // quota of bytes that can be used
1450-
Used: fs.NewUsageValue(int64(used)), // bytes in use
1451-
Free: fs.NewUsageValue(int64(total - used)), // bytes which can be uploaded before reaching the quota
1449+
Total: fs.NewUsageValue(total), // quota of bytes that can be used
1450+
Used: fs.NewUsageValue(used), // bytes in use
1451+
Free: fs.NewUsageValue(total - used), // bytes which can be uploaded before reaching the quota
14521452
}
14531453
return usage, nil
14541454
}

backend/hdfs/fs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
371371
return nil, err
372372
}
373373
return &fs.Usage{
374-
Total: fs.NewUsageValue(int64(info.Capacity)),
375-
Used: fs.NewUsageValue(int64(info.Used)),
376-
Free: fs.NewUsageValue(int64(info.Remaining)),
374+
Total: fs.NewUsageValue(info.Capacity),
375+
Used: fs.NewUsageValue(info.Used),
376+
Free: fs.NewUsageValue(info.Remaining),
377377
}, nil
378378
}
379379

backend/mega/mega.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,9 +946,9 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
946946
return nil, fmt.Errorf("failed to get Mega Quota: %w", err)
947947
}
948948
usage := &fs.Usage{
949-
Total: fs.NewUsageValue(int64(q.Mstrg)), // quota of bytes that can be used
950-
Used: fs.NewUsageValue(int64(q.Cstrg)), // bytes in use
951-
Free: fs.NewUsageValue(int64(q.Mstrg - q.Cstrg)), // bytes which can be uploaded before reaching the quota
949+
Total: fs.NewUsageValue(q.Mstrg), // quota of bytes that can be used
950+
Used: fs.NewUsageValue(q.Cstrg), // bytes in use
951+
Free: fs.NewUsageValue(q.Mstrg - q.Cstrg), // bytes which can be uploaded before reaching the quota
952952
}
953953
return usage, nil
954954
}

backend/premiumizeme/premiumizeme.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) {
793793
return nil, err
794794
}
795795
usage = &fs.Usage{
796-
Used: fs.NewUsageValue(int64(info.SpaceUsed)),
796+
Used: fs.NewUsageValue(info.SpaceUsed),
797797
}
798798
return usage, nil
799799
}

backend/sftp/sftp.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,9 +1863,9 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
18631863
free := vfsStats.FreeSpace()
18641864
used := total - free
18651865
return &fs.Usage{
1866-
Total: fs.NewUsageValue(int64(total)),
1867-
Used: fs.NewUsageValue(int64(used)),
1868-
Free: fs.NewUsageValue(int64(free)),
1866+
Total: fs.NewUsageValue(total),
1867+
Used: fs.NewUsageValue(used),
1868+
Free: fs.NewUsageValue(free),
18691869
}, nil
18701870
} else if err != nil {
18711871
if errors.Is(err, os.ErrNotExist) {

backend/smb/smb.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,11 @@ func (f *Fs) About(ctx context.Context) (_ *fs.Usage, err error) {
494494
return nil, err
495495
}
496496

497-
bs := int64(stat.BlockSize())
497+
bs := stat.BlockSize()
498498
usage := &fs.Usage{
499-
Total: fs.NewUsageValue(bs * int64(stat.TotalBlockCount())),
500-
Used: fs.NewUsageValue(bs * int64(stat.TotalBlockCount()-stat.FreeBlockCount())),
501-
Free: fs.NewUsageValue(bs * int64(stat.AvailableBlockCount())),
499+
Total: fs.NewUsageValue(bs * stat.TotalBlockCount()),
500+
Used: fs.NewUsageValue(bs * (stat.TotalBlockCount() - stat.FreeBlockCount())),
501+
Free: fs.NewUsageValue(bs * stat.AvailableBlockCount()),
502502
}
503503
return usage, nil
504504
}

0 commit comments

Comments
 (0)