From b64e20fe58da8d9afecda06c2d701096b267cca0 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 3 Mar 2026 23:12:15 +0200 Subject: Task 352: expand comprehensive test coverage --- internal/duration/parse.go | 8 ++++++++ internal/duration/parse_test.go | 2 ++ 2 files changed, 10 insertions(+) (limited to 'internal/duration') diff --git a/internal/duration/parse.go b/internal/duration/parse.go index f2febe8..f144ac1 100644 --- a/internal/duration/parse.go +++ b/internal/duration/parse.go @@ -11,6 +11,11 @@ import ( var bareIntegerPattern = regexp.MustCompile(`^[+-]?\d+$`) +const ( + maxInt64 = int64(^uint64(0) >> 1) + minInt64 = -maxInt64 - 1 +) + // Parse converts duration text into time.Duration. // Go-style durations (e.g. "1h30m") are supported, and bare integers are seconds. func Parse(value string) (time.Duration, error) { @@ -24,6 +29,9 @@ func Parse(value string) (time.Duration, error) { if err != nil { return 0, fmt.Errorf("parse seconds %q: %w", value, err) } + if seconds > maxInt64/int64(time.Second) || seconds < minInt64/int64(time.Second) { + return 0, fmt.Errorf("duration seconds %q overflows time.Duration", value) + } return time.Duration(seconds) * time.Second, nil } diff --git a/internal/duration/parse_test.go b/internal/duration/parse_test.go index 3b812cd..931f904 100644 --- a/internal/duration/parse_test.go +++ b/internal/duration/parse_test.go @@ -63,6 +63,8 @@ func TestParseInvalidDurations(t *testing.T) { " ", "abc", "1h30x", + "9223372036854775807", + "-9223372036854775808", } for _, input := range tests { -- cgit v1.2.3