-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Preventing stack overflow exceptions via limiting the depth of the parser rules #3112
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
Conversation
…rser rules - moving to 500 deep as a starting point
| ParserOptions.setDefaultParserOptions(defaultOptions) | ||
| ParserOptions.setDefaultOperationParserOptions(defaultOperationOptions) | ||
| ParserOptions.setDefaultSdlParserOptions(defaultSdlOptions) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to the Stress test class along with other stress tests
|
|
||
| boolean isEqual(List<Node> node1, List<Node> node2) { | ||
| return AstComparator.isEqual(node1, node2) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never used
| when: | ||
| def document = new Parser().parseDocument(input, parserOptionsWithoutCaptureLineComments) | ||
| def parserEnvironment = newParserEnvironment().document(input).parserOptions(parserOptionsWithoutCaptureLineComments).build() | ||
| def document = new Parser().parseDocument(parserEnvironment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed deprecated methods
| document.getSourceLocation() == SourceLocation.EMPTY | ||
| document.getDefinitions()[0].getSourceLocation() == SourceLocation.EMPTY | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the following the ParserStressTest
andimarek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see one comment about Internal exception ... otherwise LGTM
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| @Internal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be public because the Parser throws it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well it has to be since its in another package (with the others)
exceptions
InvalidUnicodeSyntaxException
MoreTokensSyntaxException
ParseCancelledException
ParseCancelledTooDeepException
Merge pull request #3112 from graphql-java/prevent-stackoverflow-in-parser Preventing stack overflow exceptions via limiting the depth of the parser rules # Conflicts: # src/main/java/graphql/parser/Parser.java # src/main/java/graphql/parser/ParserOptions.java # src/main/resources/i18n/Parsing.properties # src/test/groovy/graphql/parser/ParserTest.groovy
Merge pull request #3112 from graphql-java/prevent-stackoverflow-in-parser Preventing stack overflow exceptions via limiting the depth of the parser rules # Conflicts: # src/main/java/graphql/parser/Parser.java # src/main/java/graphql/parser/ParserOptions.java # src/main/resources/i18n/Parsing.properties # src/test/groovy/graphql/parser/ParserTest.groovy
This puts in a limit on how deep grammar rules can get.
As ANLTR is a recursive-descent parser it will build up a call stack as it moves along. This stack is limited and can blow up with just the wrong input. Even if the max tokens checking is in place, it can still blow the JVM stack before the max tokens are reached.
Right now it's 500 deep as presented here. Is this the right value? More?? Less ?? I changed it from 1000