-
Notifications
You must be signed in to change notification settings - Fork 72
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
Incorrect nanosecond serialization for very large or small values #771
Comments
I was planning to open another issue for having a |
Thank you for the report. Yes, there is indeed a problem here. The code uses the normal math operations and some How did you come up with those time values to test? I wonder if you have a list of such strings/timestamps or if you used automated tools. I do want to fix the issue, but it might take a while. It seems to require some steps
|
I used binary search to find these edges between behaviors. I don't know if there's a list of such timestamps, but 9,223,372,036,854,775,807 is the limit of an i64 so those are probably good values to check for any implementation. |
TimestampNanoSeconds
has the following serialization behavior:..1385-06-12T00:25:26.290448385Z
: panicoverflow when multiplying duration by scalar
1385-06-12T00:25:26.290448385Z..1677-09-21T00:12:43.145224192Z
: incorrect positive value1677-09-21T00:12:43.145224192Z
: panicattempt to negate with overflow
1677-09-21T00:12:43.145224193Z..2262-04-11T23:47:16.854775808Z
: correct2262-04-11T23:47:16.854775808Z..2554-07-21T23:34:33.709551616Z
: incorrect negative value2554-07-21T23:34:33.709551616Z..
: panicoverflow when multiplying duration by scalar
Not being able to serialize values outside the range
1677-09-21T00:12:43.145224193Z..2262-04-11T23:47:16.854775808Z
is expected since it's serializing to an i64, but if the value is outside that range it should return an error, not panic or return incorrect values.A similar problem exists with
TimestampNanoSecondsWithFrac
:..1385-06-12T00:25:26.290448385Z
: panicoverflow when multiplying duration by scalar
1385-06-12T00:25:26.290448385Z..2554-07-21T23:34:33.709551616Z
: correct2554-07-21T23:34:33.709551616Z..
: panicoverflow when multiplying duration by scalar
TimeStampNanoSecondsWithFrac
should never fail because it is serializing to f64 and f64 can represent much larger values, at the expense of precision.The other
TimeStamp*
serializers are not affected because the range of values that can be represented byDateTime
is smaller than the range of values that can be represented by ani64
.DurationNanoSeconds
andDurationNanoSecondsFrac
also have a similar problem:..18446744073.709551616s
: correct18446744073.709551616s..
: panic:overflow when multiplying duration by scalar
DurationNanoSeconds
should return an error instead of panicking, andDurationNanoSecondsFrac
should never fail.DurationMicroSeconds
andDurationMicroSecondsFrac
fail the same way for18446744073709.551616s..
.18446744073709551.616s..
forDurationMilliSeconds
andDurationMilliSecondsWithFrac
.DurationSeconds
andDurationSecondsWithFrac
are unaffected.The text was updated successfully, but these errors were encountered: