Skip to content
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

Fixed integer overflow in NumericDate.MarshalJSON #200

Merged

Commits on May 2, 2022

  1. Fixed integer overflow in NumericDate.MarshalJSON

    The original issue was caused by the fact that if we use a very large
    unix timestamp. The resulting value from time.UnixNano overflows a
    int64, as documented here: https://pkg.go.dev/time#Time.UnixNano.
    
    This patch works around the issue by calculating the second part and
    nanosecond part separately, taking the second part from time.Unix,
    and the nanosecond part from time.Nanosecond and then adding the
    results together.
    qqiao committed May 2, 2022
    Copy the full SHA
    915a781 View commit details
    Browse the repository at this point in the history

Commits on May 3, 2022

  1. Supporting even larger timestamps

    We now format the whole part and the decimal part separately.
    
    Since the whole part is by definition, we need not covert it to a float,
    hence the whole part can simply be formatted as an integer.
    
    The and since by definition of the `Time.Nanoseconds()`, the return
    value is between 0-999999999, only this part needs to be formatted
    separately.
    
    We then combine whole + decimals[1:] to form the final result.
    
    This allows us to correctly format the maximun timestamp that is allowed
    by Go.
    qqiao committed May 3, 2022
    Copy the full SHA
    eb2e058 View commit details
    Browse the repository at this point in the history

Commits on May 30, 2022

  1. Added source code comments to document the reason for the approach

    used to marshal times.
    
    Improved variable naming and fixed typos.
    qqiao committed May 30, 2022
    Copy the full SHA
    585fa25 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    769fec9 View commit details
    Browse the repository at this point in the history

Commits on May 31, 2022

  1. Copy the full SHA
    bf78efc View commit details
    Browse the repository at this point in the history