Preventing stack overflow exceptions via limiting the depth of the parser rules#3112
Merged
Preventing stack overflow exceptions via limiting the depth of the parser rules#3112
Conversation
…rser rules - moving to 500 deep as a starting point
bbakerman
commented
Mar 13, 2023
| ParserOptions.setDefaultParserOptions(defaultOptions) | ||
| ParserOptions.setDefaultOperationParserOptions(defaultOperationOptions) | ||
| ParserOptions.setDefaultSdlParserOptions(defaultSdlOptions) | ||
| } |
Member
Author
There was a problem hiding this comment.
Moved to the Stress test class along with other stress tests
bbakerman
commented
Mar 13, 2023
|
|
||
| boolean isEqual(List<Node> node1, List<Node> node2) { | ||
| return AstComparator.isEqual(node1, node2) | ||
| } |
bbakerman
commented
Mar 13, 2023
| when: | ||
| def document = new Parser().parseDocument(input, parserOptionsWithoutCaptureLineComments) | ||
| def parserEnvironment = newParserEnvironment().document(input).parserOptions(parserOptionsWithoutCaptureLineComments).build() | ||
| def document = new Parser().parseDocument(parserEnvironment) |
Member
Author
There was a problem hiding this comment.
removed deprecated methods
bbakerman
commented
Mar 13, 2023
| document.getSourceLocation() == SourceLocation.EMPTY | ||
| document.getDefinitions()[0].getSourceLocation() == SourceLocation.EMPTY | ||
| } | ||
|
|
Member
Author
There was a problem hiding this comment.
Moved the following the ParserStressTest
dondonz
approved these changes
Mar 14, 2023
temaEmelyan
approved these changes
Mar 16, 2023
russellyou
approved these changes
Mar 16, 2023
andimarek
approved these changes
Mar 20, 2023
Member
andimarek
left a comment
There was a problem hiding this comment.
see one comment about Internal exception ... otherwise LGTM
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| @Internal |
Member
There was a problem hiding this comment.
should this be public because the Parser throws it?
Member
Author
There was a problem hiding this comment.
well it has to be since its in another package (with the others)
exceptions
InvalidUnicodeSyntaxException
MoreTokensSyntaxException
ParseCancelledException
ParseCancelledTooDeepException
bbakerman
added a commit
that referenced
this pull request
Mar 20, 2023
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
bbakerman
added a commit
that referenced
this pull request
Mar 20, 2023
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 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 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