From a2aa65562708b29e472f5a175195d264d9ab16f1 Mon Sep 17 00:00:00 2001 From: PiotrKozimor <37144818+PiotrKozimor@users.noreply.github.com> Date: Wed, 27 Oct 2021 03:14:01 +0200 Subject: [PATCH] Fix int64 overflow in newNumericDateFromSeconds (#112) --- types.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types.go b/types.go index 15c39a3..80b1b96 100644 --- a/types.go +++ b/types.go @@ -3,6 +3,7 @@ package jwt import ( "encoding/json" "fmt" + "math" "reflect" "strconv" "time" @@ -41,7 +42,8 @@ func NewNumericDate(t time.Time) *NumericDate { // newNumericDateFromSeconds creates a new *NumericDate out of a float64 representing a // UNIX epoch with the float fraction representing non-integer seconds. func newNumericDateFromSeconds(f float64) *NumericDate { - return NewNumericDate(time.Unix(0, int64(f*float64(time.Second)))) + round, frac := math.Modf(f) + return NewNumericDate(time.Unix(int64(round), int64(frac*1e9))) } // MarshalJSON is an implementation of the json.RawMessage interface and serializes the UNIX epoch