From a89766467ea3c1fab84f30da43b35f042af7a1c9 Mon Sep 17 00:00:00 2001 From: Soujas K Date: Wed, 28 Oct 2026 12:18:36 +0530 Subject: [PATCH] fs: reject NaN durations instead of wrapping strconv.ParseFloat accepts "NaN", and NaN compares false with every bound, so it got past the overflow check added for 300y and was then converted to a time.Duration, which gives the minimum int64 on amd64. --max-age NaN or --min-age NaNM silently became about -292 years, which moves the filter's ModTimeFrom into the future and excludes every file, instead of being rejected. --- fs/parseduration.go | 3 +++ fs/parseduration_test.go | 3 +++ 2 files changed, 6 insertions(+) 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},