Skip to content

Commit

Permalink
Fix int64 overflow in newNumericDateFromSeconds (golang-jwt#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrKozimor authored and oxisto committed Feb 21, 2023
1 parent efc77e6 commit 06bad75
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion types.go
Expand Up @@ -3,6 +3,7 @@ package jwt
import (
"encoding/json"
"fmt"
"math"
"reflect"
"strconv"
"time"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 06bad75

Please sign in to comment.