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

Fixes int overflow issue for large TTL values #3367

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

vy8
Copy link
Contributor

@vy8 vy8 commented Aug 14, 2021

Fixes #3357.

The line indexTtl * 1000 will produce an integer overflow for large indexTtl values. For example 7890000 * 1000 will produce an integer overflow (some negative number).

The simple fix is to use long in the multiplication.

@jcchavezs
Copy link
Contributor

jcchavezs commented Aug 15, 2021 via email

@jcchavezs
Copy link
Contributor

@vy8 could you add a unit test for this?

@vy8 vy8 force-pushed the fix-int-overflow branch from b07b3d3 to d88d40b Compare December 5, 2021 16:01
@vy8
Copy link
Contributor Author

vy8 commented Dec 5, 2021

Hey @jcchavezs just did. Even thought it's a simple test that checks if startMillis is smaller than endMillis it will fail with the old code that doesn't have the explicit 'L' for long.

@@ -305,8 +305,8 @@
UUID endUUID;
}

TimestampRange timestampRange(QueryRequest request) {
long oldestData = Math.max(System.currentTimeMillis() - indexTtl * 1000, 0); // >= 1970
TimestampRange timestampRange(QueryRequest request, int indexTtl) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@vy8 vy8 Dec 12, 2021

Choose a reason for hiding this comment

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

@jcchavezs the indexTtl value comes from a static method and then gets set to a final class attribute. To create a test I need to either:
a) Set the property using reflection for the test.
b) Mock a static method.
c) Pass the indexTtl as a param.

I chose c) since it seemed as the least amount of hassle. Tell me which option you would prefer and I'll implement it.
Cheers!

@jcchavezs
Copy link
Contributor

Somehow the test is failing. Would you please look into it?

@vy8 vy8 force-pushed the fix-int-overflow branch from d88d40b to 7c5d761 Compare December 13, 2021 16:58
@vy8
Copy link
Contributor Author

vy8 commented Dec 13, 2021

@jcchavezs bumped the year in the license from 2020 to 2021 and all should be good.

@codefromthecrypt codefromthecrypt merged commit 68c4949 into openzipkin:master Dec 6, 2023
@codefromthecrypt
Copy link
Member

thanks. will be in next release

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.

timestampRange calculation error due to int variable instead of long
3 participants