Visitar URL original
fix(engine): reject duration values that wrap time.Duration by weirong-ui · Pull Request #32841 · helm/helm · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/engine/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ func durationFromSecondsFloat(seconds float64) (time.Duration, error) {
return 0, fmt.Errorf("duration seconds overflow: %v", seconds)
}
nanos := seconds * float64(time.Second)
if nanos > float64(math.MaxInt64) || nanos < float64(math.MinInt64) {
// float64(math.MaxInt64) rounds up to 2^63, which wraps when converted.
if nanos >= float64(math.MaxInt64) || nanos < float64(math.MinInt64) {
return 0, fmt.Errorf("duration nanoseconds overflow: %v", nanos)
}
return time.Duration(nanos), nil
Expand Down
9 changes: 9 additions & 0 deletions pkg/engine/funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ func TestDurationHelpers(t *testing.T) {
tpl: `{{ durationSeconds . }}`,
vars: maxDurationSecondsFloat + 0.5,
expect: `0`,
}, {
name: "durationSeconds float at upper boundary returns 0",
tpl: `{{ durationSeconds . }}`,
vars: maxDurationSecondsFloat,
expect: `0`,
}, {
name: "durationSeconds float underflow returns 0",
tpl: `{{ durationSeconds . }}`,
Expand Down Expand Up @@ -425,6 +430,10 @@ func TestDurationHelpers(t *testing.T) {
name: "mustToDuration float overflow",
tpl: `{{ mustToDuration . }}`,
vars: maxDurationSecondsFloat + 0.5,
}, {
name: "mustToDuration float at upper boundary",
tpl: `{{ mustToDuration . }}`,
vars: maxDurationSecondsFloat,
}, {
name: "mustToDuration float underflow",
tpl: `{{ mustToDuration . }}`,
Expand Down
Loading