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

fs: reject sizes too large for SizeSuffix instead of silently disabling the limit

KBSc4f4dbf3ecd6
diff --git a/fs/sizesuffix.go b/fs/sizesuffix.go
index c8d454e81..f725138db 100644
--- a/fs/sizesuffix.go
+++ b/fs/sizesuffix.go
@@ -181,6 +181,9 @@ func (x *SizeSuffix) Set(s string) error {
return fmt.Errorf("size can't be negative %q", s)
}
value *= multiplier
+ if value >= float64(SizeSuffixMaxValue) {
+ return fmt.Errorf("value can't be greater than %d", int64(SizeSuffixMaxValue))
+ }
*x = SizeSuffix(value)
return nil
}
diff --git a/fs/sizesuffix_test.go b/fs/sizesuffix_test.go
index 732ec4372..3a895475e 100644
--- a/fs/sizesuffix_test.go
+++ b/fs/sizesuffix_test.go
@@ -116,6 +116,11 @@ func TestSizeSuffixSet(t *testing.T) {
{"10G", 10 * 1024 * 1024 * 1024, false},
{"10T", 10 * 1024 * 1024 * 1024 * 1024, false},
{"10P", 10 * 1024 * 1024 * 1024 * 1024 * 1024, false},
+ {"7E", 7 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, false},
+ {"8E", 0, true},
+ {"8Ei", 0, true},
+ {"8EiB", 0, true},
+ {"10E", 0, true},
{"off", -1, false},
{"OFF", -1, false},
{"", 0, true},