-
Notifications
You must be signed in to change notification settings - Fork 7
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
Fail fast on integer overflow #549
Conversation
Generate changelog in
|
throw new SafeIllegalStateException( | ||
"Can't parse segment as integer as it overflowed", | ||
SafeArg.of("string", string), | ||
SafeArg.of("segment", string.substring(groupStart, groupEnd))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pedantic nit: We may want to extract this to a integerOverflow(String,int,int);
function to cut negative test data out of hot paths for better inlining
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Released 1.3.0 |
Before this PR
In PDS-235827, we've encountered some version strings which are constructed by doing
x.y.yymmddhhmm
. It turns out this was fine last year, but now produces numbers like1.1.2201051644
which is larger than Integer.MAX_VALUE. The consequence is a bit scary - in the latest version of sls-version-java we'll actually tolerate these, but internally when we store the.patchVersionNumber(groups.groupAsInt(3));
, the giant integer overflows to becoem a negative number so they SORT WRONG.After this PR
==COMMIT_MSG==
OrderableSlsVersion.valueOf
will now refuse to interpret a version string containing a number greater than Integer.MAX_VALUE as a valid orderable version.==COMMIT_MSG==
The reason I want to fail hard rather than try to relax this is because the abstract
SlsVersion
class imposes these fun methods which all mention integers, and I have no interest in causing an ABI break just for this.Possible downsides?