diff options
author | Rob Pike <r@golang.org> | 2016-09-18 14:35:42 +1000 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2016-09-19 19:46:09 +0000 |
commit | 3cca069220af044c1a36da3f588ffe3abbeab9c5 (patch) | |
tree | 65b4fe54144842476a11fa1a26b64701244e6b70 /src/time/time_test.go | |
parent | e94c52933b9c414d3f8fa94ead0d9cc5b7d7d717 (diff) | |
download | go-3cca069220af044c1a36da3f588ffe3abbeab9c5.tar.gz go-3cca069220af044c1a36da3f588ffe3abbeab9c5.zip |
time: allow long fractions in ParseDuration
The code scanned for an integer after a decimal point, which
meant things could overflow if the number was very precise
(0.1234123412341234123412342134s). This fix changes the
parser to stop adding precision once we run out of bits, rather
than trigger an erroneous overflow.
We could parse durations using floating-point arithmetic,
but since the type is int64 and float64 has only has 53 bits
of precision, that would be imprecise.
Fixes #15011.
Change-Id: If85e22b8f6cef12475e221169bb8f493bb9eb590
Reviewed-on: https://go-review.googlesource.com/29338
Reviewed-by: Costin Chirvasuta <costinc@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/time/time_test.go')
-rw-r--r-- | src/time/time_test.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/time/time_test.go b/src/time/time_test.go index fcc28ee99c..68236fd64d 100644 --- a/src/time/time_test.go +++ b/src/time/time_test.go @@ -840,6 +840,10 @@ var parseDurationTests = []struct { {"9223372036s854ms775us807ns", true, (1<<63 - 1) * Nanosecond}, // large negative value {"-9223372036854775807ns", true, -1<<63 + 1*Nanosecond}, + // huge string; issue 15011. + {"0.100000000000000000000h", true, 6 * Minute}, + // This value tests the first overflow check in leadingFraction. + {"0.830103483285477580700h", true, 49*Minute + 48*Second + 372539827*Nanosecond}, // errors {"", false, 0}, |