summaryrefslogtreecommitdiff
path: root/internal/duration/parse.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/duration/parse.go')
-rw-r--r--internal/duration/parse.go8
1 files changed, 8 insertions, 0 deletions
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
}