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 possible regex matching stack overflow #2150

Merged
merged 2 commits into from Aug 8, 2023

Conversation

arthurscchan
Copy link
Contributor

This fixes a possible StackOverflowError in regex parsing of long expressions in core/src/main/java/feign/template/Expressions.java.

Java regex matchers are known to be recursive. When it handles some complicated structure like repetitive alternative paths (a|b)* on long string input, its recursive structure will fill up the stack fast. This will result in StackOverflowError. In Expressions.java, its EXPRESSION_PATTERN and VARIABLE_LIST_PATTERN do contain some complicated structure. Thus when a long enough string passed in for regex matching, it will fill up the stack and crash the JVM with a StackOverflowError.

This PR reduces the possibility of the StackOverflowError by introducing a maximum length check for the expression string. Whenever the string is longer than the maximum length, the parser will not run and simply throw an IllegalArgumentException. This could avoid a long string regex matching with those complicated patterns resulting in StackOverflowException and crashing the JVM.

An additional unit test case has been added for testing the changed behaviour.

We found this bug using fuzzing by way of OSS-Fuzz, where we recently integrated Feign (google/oss-fuzz#10684). 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.

@velo velo merged commit fc6bf6f into OpenFeign:master Aug 8, 2023
3 checks passed
@arthurscchan arthurscchan deleted the fix-regex-stack-overflow branch August 8, 2023 19:17
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