diff --git a/fs/parseduration.go b/fs/parseduration.go index 1ae778125..005b888e8 100644 --- a/fs/parseduration.go +++ b/fs/parseduration.go @@ -61,6 +61,9 @@ func parseDurationSuffixes(age string) (time.Duration, error) { if err != nil { return time.Duration(0), err } + if math.IsNaN(period) { + return time.Duration(0), fmt.Errorf("duration %q is not a number", age) + } period *= float64(ageSuffix.Multiplier) if math.Abs(period) >= math.MaxInt64 { return time.Duration(0), fmt.Errorf("duration %q is too long", age) diff --git a/fs/parseduration_test.go b/fs/parseduration_test.go index 915d40532..ba285a963 100644 --- a/fs/parseduration_test.go +++ b/fs/parseduration_test.go @@ -58,6 +58,9 @@ func TestParseDuration(t *testing.T) { {"300y", 0, true}, {"-300y", 0, true}, {"1e10d", 0, true}, + {"NaN", 0, true}, + {"NaNd", 0, true}, + {"-NaNM", 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},