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 durations like 300y that overflow instead of wrapping

kevin932740139a749e98
diff --git a/fs/parseduration.go b/fs/parseduration.go
index 2c03132f4..1ae778125 100644
--- a/fs/parseduration.go
+++ b/fs/parseduration.go
@@ -62,6 +62,9 @@ func parseDurationSuffixes(age string) (time.Duration, error) {
return time.Duration(0), err
}
period *= float64(ageSuffix.Multiplier)
+ if math.Abs(period) >= math.MaxInt64 {
+ return time.Duration(0), fmt.Errorf("duration %q is too long", age)
+ }
break
}
}
diff --git a/fs/parseduration_test.go b/fs/parseduration_test.go
index 2b08fe32a..915d40532 100644
--- a/fs/parseduration_test.go
+++ b/fs/parseduration_test.go
@@ -55,6 +55,9 @@ func TestParseDuration(t *testing.T) {
{"1d12x", 0, true},
{"1d-2h", 0, true},
{"300y1d", 0, true},
+ {"300y", 0, true},
+ {"-300y", 0, true},
+ {"1e10d", 0, true},
{"2001-02-03", now.Sub(time.Date(2001, 2, 3, 0, 0, 0, 0, time.Local)), false},
{"2001-02-03 10:11:12", now.Sub(time.Date(2001, 2, 3, 10, 11, 12, 0, time.Local)), false},
{"2001-08-03 10:11:12", now.Sub(time.Date(2001, 8, 3, 10, 11, 12, 0, time.Local)), false},