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 bug in array index handling #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arthurscchan
Copy link

This fixes an unwrapped ArrayIndexOutOfBoundException in src/main/java/net/objecthunter/exp4j/tokenizer/Tokenizer.java.

If the expression only contains whitespace characters, or if the expression is ended with whitespace characters. It will result in a possible ArrayIndexOutOfBoundException. This is because the while loop for skipping whitespace characters has incorrect stopping criteria. The while loop will keep running until reaching a non-whitespace character; if the remaining expression only contains whitespace, the loop will not stop at the end of the expression array and the ++pos index will be out of bound in the next iteration.

This PR adds a conditional checking to ensure an exception is thrown if nextToken method is called and only whitespace characters left in the expression to ensure the pos index used in the while loop will not be out of bound.

We found this bug using fuzzing by way of OSS-Fuzz, where we recently integrated exp4j (google/oss-fuzz#10699). 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 into detail and also set up things so you can receive emails and detailed reports when bugs are found.

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.

1 participant