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 NaN sizes and CountSuffix values that overflow

kevin932718c7de092077
diff --git a/fs/countsuffix.go b/fs/countsuffix.go
index b3e1daa9e..2af2b35ea 100644
--- a/fs/countsuffix.go
+++ b/fs/countsuffix.go
@@ -139,10 +139,16 @@ func (x *CountSuffix) Set(s string) error {
if err != nil {
return err
}
+ if math.IsNaN(value) {
+ return fmt.Errorf("size must be a number %q", s)
+ }
if value < 0 {
return fmt.Errorf("size can't be negative %q", s)
}
value *= multiplier
+ if value >= float64(CountSuffixMaxValue) {
+ return fmt.Errorf("value can't be greater than %d", int64(CountSuffixMaxValue))
+ }
*x = CountSuffix(value)
return nil
}
diff --git a/fs/countsuffix_test.go b/fs/countsuffix_test.go
index 58fca960a..c1b24df2d 100644
--- a/fs/countsuffix_test.go
+++ b/fs/countsuffix_test.go
@@ -95,6 +95,12 @@ func TestCountSuffixSet(t *testing.T) {
{"1iB", 0, true},
{"1Ki", 0, true},
{"1KiB", 0, true},
+ {"9E", 9 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000, false},
+ {"9.3E", 0, true},
+ {"10E", 0, true},
+ {"infk", 0, true},
+ {"nank", 0, true},
+ {"NaNM", 0, true},
} {
ss := CountSuffix(0)
err := ss.Set(test.in)
diff --git a/fs/sizesuffix.go b/fs/sizesuffix.go
index 123f923a2..3570385b9 100644
--- a/fs/sizesuffix.go
+++ b/fs/sizesuffix.go
@@ -190,6 +190,9 @@ func (x *SizeSuffix) Set(s string) error {
if err != nil {
return err
}
+ if math.IsNaN(value) {
+ return fmt.Errorf("size must be a number %q", s)
+ }
if value < 0 {
return fmt.Errorf("size can't be negative %q", s)
}
diff --git a/fs/sizesuffix_test.go b/fs/sizesuffix_test.go
index 3a895475e..5c7c05e49 100644
--- a/fs/sizesuffix_test.go
+++ b/fs/sizesuffix_test.go
@@ -131,6 +131,8 @@ func TestSizeSuffixSet(t *testing.T) {
{"1i", 0, true},
{"1iB", 0, true},
{"1MB", 0, true},
+ {"nank", 0, true},
+ {"NaNM", 0, true},
} {
ss := SizeSuffix(0)
err := ss.Set(test.in)