Fix invalid string input#253
Merged
gnodet merged 3 commits intofusesource:masterfrom Aug 25, 2023
Merged
Conversation
Member
|
@arthurscchan do you think you can add a simple unit test for this issue ? |
Contributor
Author
|
@gnodet Thanks for your reply. Yes I could add a unit test. Will do so soon. |
gnodet
reviewed
Aug 25, 2023
591a4ea to
d54f24e
Compare
Signed-off-by: Arthur Chan <[email protected]>
Signed-off-by: Arthur Chan <[email protected]>
d54f24e to
c7ab603
Compare
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 a possible unwrapped StringIndexOutOfBoundException in src/main/java/org/fusesource/jansi/AnsiRenderer.java.
In line 85, line 95 and line 101 of the AnsiRenderer class. The method tries to determine the necessary index j and k for doing a substring operation on the input string. If the input string is malformed, it could cause j larger than k and result in StringIndexOutOfBoundException. For example, if the EndToken appears before the BeginToken, or there is no EndToken in the input string, then j is larger than k for sure.
This PR fixes the bug by adding a conditional check before doing the substring to ensure k is larger or equals to j. Otherwise, the input string is considered as malformed and an IllegalArgumentException is thrown.
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.