New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
time: Parse incorrectly parses fractional seconds with more than 9 digits #48685
Comments
The problem is Lines 1418 to 1438 in 163871f
E.g. |
Change https://golang.org/cl/353713 mentions this issue: |
Change https://golang.org/cl/381155 mentions this issue: |
For #48685 Fixes #50806 Change-Id: Ie8be40e5794c0998538890a651ef8ec92cb72d3a Reviewed-on: https://go-review.googlesource.com/c/go/+/381155 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Paul Jolly <paul@myitcv.org.uk> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Change https://go.dev/cl/425037 mentions this issue: |
This modifies the code to match the comment such that the behavior truly is identical to stdSecond case. Also, it modifies the behavior to match the documented behavior where: Fractional seconds are truncated to nanosecond precision. Fixes #54567 Updates #48685 Change-Id: Ie64549e4372ab51624c105ad8ab4cc99b9b5a0b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/425037 Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
What version of Go are you using (
go version
)?1.17.1 (play.golang.org)
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?play.golang.org
What did you do?
https://play.golang.org/p/S21r1Xz1VlZ
What did you expect to see?
either fractional seconds truncated to nanosecond precision:
or fractional seconds rounded to nearest nanosecond:
or an error in both cases.
What did you see instead?
It appears that if more than 9 digits are provided for the fractional second part, they are interpreted all together as a numeric value for the nanoseconds part, regardless of leading zeros. Thus
.0012345678Z
is interpreted the same as.012345678Z
.Also, when more than 9 significant digits are provided, rather than truncating or rounding to the nearest nanosecond, parsing produces a
fractional second out of range
error because this error condition is triggered:go/src/time/format.go
Lines 1426 to 1428 in 163871f
This bug affects
json.Unmarshal
/time.UnmarshalJSON
which uses the RFC3339 format internally:go/src/time/time.go
Line 1305 in 163871f
The code at fault is probably one or more of these call sites of parseNanoseconds:
go/src/time/format.go
Lines 1082 to 1086 in 163871f
go/src/time/format.go
Lines 1194 to 1201 in 163871f
go/src/time/format.go
Lines 1209 to 1215 in 163871f
The text was updated successfully, but these errors were encountered: