-
Notifications
You must be signed in to change notification settings - Fork 356
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
NumericDate.MarshalJSON overflows on large unix timestamps #199
Comments
I can't seem to reproduce this on my local machine. Can you provide a repro (ideally as a test that runs in CI)? Also, can you specify the system you're on and arch? package main
import (
"fmt"
"time"
"github.com/golang-jwt/jwt/v4"
)
func main() {
original := time.Unix(253402271999, 0)
date := jwt.NewNumericDate(original)
fmt.Println(date.Unix())
// 253402271999
} |
This will consistently fail on a M1 Mac:
Output would be |
I figured out the reason: the timestamp is too large, which causes |
Thanks for providing a repro and submitting a PR. Indeed that's the result of |
Using The issue with using either Internally, the The other note-worthy issue with directly taking either
When we use the value from However, the PR that I submitted avoids this issue since the value returned by To summarize, by treating the second component and nanosecond component of a |
Marshalling
NewNumericDate(time.Unix(253402271999, 0))
will result in-4852145033
instead of253402271999
Updates:
This is due to the fact that
Time.UnixNano()
overflows, andNumericDate.MarshalJSON()
internally uses this method.PR #200 created to workaround this std library limitation.
The text was updated successfully, but these errors were encountered: