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

Fix invalid string input #253

Merged
merged 3 commits into from Aug 25, 2023
Merged

Conversation

arthurscchan
Copy link
Contributor

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.

@gnodet gnodet added this to the 2.5.0 milestone Aug 22, 2023
@gnodet
Copy link
Member

gnodet commented Aug 22, 2023

@arthurscchan do you think you can add a simple unit test for this issue ?

@arthurscchan
Copy link
Contributor Author

@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>
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
@gnodet gnodet merged commit 58260c6 into fusesource:master Aug 25, 2023
6 checks passed
@gnodet gnodet modified the milestones: 2.5.0, 2.4.1 Oct 12, 2023
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.

None yet

2 participants