Fix infinite loop bug#252
Merged
gnodet merged 5 commits intofusesource:masterfrom Aug 25, 2023
Merged
Conversation
Signed-off-by: Arthur Chan <[email protected]>
gnodet
requested changes
Aug 22, 2023
Member
|
Thx, could you add an additional unit test ? that would be awesome @arthurscchan |
Signed-off-by: Arthur Chan <[email protected]>
Contributor
Author
|
@gnodet Thanks for your reply. Yes I could add a unit test. Will do so soon. |
Signed-off-by: Arthur Chan <[email protected]>
bf8bd98 to
4753292
Compare
gnodet
reviewed
Aug 25, 2023
gnodet
reviewed
Aug 25, 2023
Signed-off-by: Arthur Chan <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes an infinite loop bug in src/main/java/org/fusesource/jansi/Ansi.java.
The
scrollUp(int)andscrollDown(int)methods first check the input and determine what value to return. If a negative row number is provided, the method will use a minus sign to change it to a positive number and call its counterpart to handle. In general, this has no problem at all. But if the provided number isInteger.MIN_VALUE, which is-2147483648, it will create an infinite loop. The main reason is-(-2147483648)=2147483648. But the max value of integer is only2147483647in java. Thus the number2147483648will wrap around and become-2147483648again. This creates an infinite loop because the number always remains negative.This PR fixes this possible bug by adding a conditional checking to ensure
Integer.MIN_VALUEis changed toInteger.MAX_VALUEbefore calling the counterpart method to avoid the infinite loop.We found this bug using fuzzing by way of OSS-Fuzz, where we recently integrated jansi (google/oss-fuzz#10705). OSS-Fuzz is a free service run by Google for fuzzing important open source software. If you'd like to know more about this then I'm happy to go in details and also set up things so you can receive emails and detailed reports when bugs are found.