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

changed Itoa to Sprintf to allow int64 value preventing 2038 overflow #12788

Merged
merged 5 commits into from
Oct 9, 2024

Conversation

vtrenton
Copy link
Contributor

@vtrenton vtrenton commented Feb 8, 2024

What this PR does / why we need it:
Prevents an overflow when getting Unix time past the year 2038

Special notes for your reviewer:
I'm very open to recommendations on how to better fix this problem. We should probably replace Itoa() used for time anywhere to avoid this problem in the future :). I tested everything here: https://play.golang.com/p/y4HMAegdQ_r

closes #12786

Signed-off-by: Trenton VanderWert <trenton.vanderwert@gmail.com>
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Feb 8, 2024
@ganesh-karthick
Copy link

ganesh-karthick commented Feb 8, 2024

Another option https://play.golang.com/p/944m5DvpxD-

// Format it as a string
	str := fmt.Sprintf("%v", t.Unix())

@pull-request-size pull-request-size bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 9, 2024
@pull-request-size pull-request-size bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 9, 2024
Signed-off-by: Trenton VanderWert <trenton.vanderwert@gmail.com>
@pull-request-size pull-request-size bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 9, 2024
@vtrenton
Copy link
Contributor Author

vtrenton commented Feb 9, 2024

found and cleaned up the occurences of the overflow in the configmap file as well. I dont see any others with a quick grep so that should cover all the use cases. switched to the sprintf. note this brings "fmt" into scope.

@yxxhero yxxhero added this to the 3.14.1 milestone Feb 10, 2024
@vtrenton vtrenton changed the title changed Iota to FormatInt to allow int64 value preventing 2038 overflow changed Itoa to FormatInt to allow int64 value preventing 2038 overflow Feb 12, 2024
@vtrenton vtrenton changed the title changed Itoa to FormatInt to allow int64 value preventing 2038 overflow changed Itoa to Sprintf to allow int64 value preventing 2038 overflow Feb 12, 2024
Copy link

@tleed5 tleed5 left a comment

Choose a reason for hiding this comment

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

I'm not a contributor or maintainer on this project so take all of this with a grain of salt.

Since there is quite a few places where this time -> string conversion occurs it might be better to encapsulate this into a method in pkg/time something like

func (t Time) FormatAsString() string

That way all of the time formatting stuff is kept together and you won't have to import the fmt package everywhere.

Extra benefit is that you would be easily be able to add unit tests to cover the issue this is fixing 😄

@vtrenton
Copy link
Contributor Author

I am an absolute noob and set up another branch have been attempting to do this (but running into problems with the imports). Thinking through it I think you're right @tleed5 - there are several other useful functions in /pkg/time so it would make a lot of sense to add this as yet another helper function or method. For the sake of this PR, I don't want to do any "large" refeactoring unless instructed by the maintainers. But I might open a seperate PR for this. Thanks for the tip!

Copy link
Contributor

@gjenkins8 gjenkins8 left a comment

Choose a reason for hiding this comment

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

can we include a test to show the issue is fixed, and prevent a regression in the future please

@vtrenton
Copy link
Contributor Author

ok so while trying to reproduce - I have found that I may be fundementally misunderstanding the issue here. It seems that in go int and int64 are both 64bit while running on a 64bit system. which means the original code I'm attempting to patch in this PR doesn't actually do anything here. Here are a couple go playground links showing this:
https://play.golang.com/p/sM8eIJ8efqs
https://play.golang.com/p/gmfV1LE4rkZ
I'm starting to think the issue is instead - the requester of the issue might be running kubernetes on a 32bit system...

@mattfarina mattfarina modified the milestones: 3.14.3, 3.14.4 Mar 13, 2024
@mattfarina mattfarina modified the milestones: 3.14.4, 3.15.0 Apr 10, 2024
@mattfarina mattfarina modified the milestones: 3.15.0, 3.16.0 Jun 12, 2024
@scottrigby scottrigby modified the milestones: 3.16.0, 3.17.0 Sep 11, 2024
Copy link
Collaborator

@mattfarina mattfarina left a comment

Choose a reason for hiding this comment

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

There is still one place that is no 2038 ready and this is the SQL driver that needs to be moved to a BIGINT. I think this can happen in a separate PR.

@mattfarina
Copy link
Collaborator

Note, the force-push contained no changes. It was just used to trigger CI.

@mattfarina
Copy link
Collaborator

@gjenkins8 In order to test this you would need to set the system clock to a time after 2038 in order to get a unix time that can't be represented as a 32-bit int. We don't have the ability to change the clock in most testing environments.

@mattfarina mattfarina added the Has One Approval This PR has one approval. It still needs a second approval to be merged. label Oct 7, 2024
Copy link
Contributor

@robertsirc robertsirc left a comment

Choose a reason for hiding this comment

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

LGTM

@mattfarina mattfarina merged commit 54be551 into helm:main Oct 9, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Has One Approval This PR has one approval. It still needs a second approval to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Helm getting into year 2038 issue
8 participants