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

Fix int64 overflow in newNumericDateFromSeconds #112

Merged
merged 1 commit into from
Oct 27, 2021

Conversation

PiotrKozimor
Copy link
Contributor

int64(f*float64(time.Second)) may easily overflow (this bug occured for me when validating token). I suggest here alternative approach to parse NumericDate.

Copy link
Collaborator

@oxisto oxisto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks to be a good alternative.

@PiotrKozimor
Copy link
Contributor Author

Thanks, can you merge it? I don't have such a possibility.

@oxisto
Copy link
Collaborator

oxisto commented Oct 26, 2021

Thanks, can you merge it? I don't have such a possibility.

We usually want to have two reviews before we merge it.

cc @mfridman @lggomez

@mfridman
Copy link
Member

mfridman commented Oct 27, 2021

Are you using 200y tokens, i.e., overflowing sometime in 2200's 😛

Thanks @PiotrKozimor

@mfridman mfridman merged commit a2aa655 into golang-jwt:main Oct 27, 2021
@PiotrKozimor PiotrKozimor deleted the fix/int64-overflow branch October 27, 2021 05:58
@tiramiseb
Copy link

Hello,

I just debugged the same line locally :-)

However, I think there is no need to extract nanoseconds, because the NewNumericDate function which is called truncates the time... with a TimePrecision of 1 second.

Thus, I was going to create a PR that would simply have the following:

func newNumericDateFromSeconds(f float64) *NumericDate {
	return NewNumericDate(time.Unix(int64(f), 0))
}

@tiramiseb
Copy link

tiramiseb commented Oct 29, 2021

Are you using 200y tokens, i.e., overflowing sometime in 2200's 😛

yep, in unit-tests, to be absolutely sure a token would never expire in tests.

I know, it's a bit overkill, but well...

@oxisto
Copy link
Collaborator

oxisto commented Oct 29, 2021

Hello,

I just debugged the same line locally :-)

However, I think there is no need to extract nanoseconds, because the NewNumericDate function which is called truncates the time... with a TimePrecision of 1 second.

Thus, I was going to create a PR that would simply have the following:

func newNumericDateFromSeconds(f float64) *NumericDate {
	return NewNumericDate(time.Unix(int64(f), 0))
}

You can configure the truncating precision. Default is second but there was a request to support adjusting it. So the original approach in this PR should be ok.

@tiramiseb
Copy link

You can configure the truncating precision. Default is second but there was a request to support adjusting it. So the original approach in this PR should be ok.

Thanks! Indeed, if the truncating precision is meant to be modified, my suggestion is not okay 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants