mirror of
https://github.com/golang/go
synced 2024-11-23 05:10:09 -07:00
time: handle int64 overflow in ParseDuration.
Previously, passing a long duration to ParseDuration could result in random, even negative, values. LGTM=r R=golang-codereviews, bradfitz, r CC=golang-codereviews https://golang.org/cl/72120043
This commit is contained in:
parent
4bc632cead
commit
4ca6e588e4
@ -1240,5 +1240,8 @@ func ParseDuration(s string) (Duration, error) {
|
||||
if neg {
|
||||
f = -f
|
||||
}
|
||||
if f < float64(-1<<63) || f > float64(1<<63-1) {
|
||||
return 0, errors.New("time: overflow parsing duration")
|
||||
}
|
||||
return Duration(f), nil
|
||||
}
|
||||
|
@ -842,6 +842,7 @@ var parseDurationTests = []struct {
|
||||
{"-.", false, 0},
|
||||
{".s", false, 0},
|
||||
{"+.s", false, 0},
|
||||
{"3000000h", false, 0}, // overflow
|
||||
}
|
||||
|
||||
func TestParseDuration(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user