-
Notifications
You must be signed in to change notification settings - Fork 139
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 infinite loop bug #252
Merged
Merged
Conversation
This file contains 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
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
gnodet
requested changes
Aug 22, 2023
Thx, could you add an additional unit test ? that would be awesome @arthurscchan |
@gnodet Thanks for your reply. Yes I could add a unit test. Will do so soon. |
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
arthurscchan
force-pushed
the
fix-number-overflow
branch
from
August 22, 2023 14:55
bf8bd98
to
4753292
Compare
gnodet
reviewed
Aug 25, 2023
gnodet
reviewed
Aug 25, 2023
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
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 only2147483647
in java. Thus the number2147483648
will wrap around and become-2147483648
again. 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_VALUE
is changed toInteger.MAX_VALUE
before 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.