Skip to content

Commit a2aa655

Browse files
authored
Fix int64 overflow in newNumericDateFromSeconds (#112)
1 parent c0ffb89 commit a2aa655

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package jwt
33
import (
44
"encoding/json"
55
"fmt"
6+
"math"
67
"reflect"
78
"strconv"
89
"time"
@@ -41,7 +42,8 @@ func NewNumericDate(t time.Time) *NumericDate {
4142
// newNumericDateFromSeconds creates a new *NumericDate out of a float64 representing a
4243
// UNIX epoch with the float fraction representing non-integer seconds.
4344
func newNumericDateFromSeconds(f float64) *NumericDate {
44-
return NewNumericDate(time.Unix(0, int64(f*float64(time.Second))))
45+
round, frac := math.Modf(f)
46+
return NewNumericDate(time.Unix(int64(round), int64(frac*1e9)))
4547
}
4648

4749
// MarshalJSON is an implementation of the json.RawMessage interface and serializes the UNIX epoch

0 commit comments

Comments
 (0)