Skip to content

Conversation

@bbakerman
Copy link
Member

@bbakerman bbakerman commented Mar 13, 2023

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

@bbakerman bbakerman added this to the 20.1 milestone Mar 13, 2023
…rser rules - moving to 500 deep as a starting point
ParserOptions.setDefaultParserOptions(defaultOptions)
ParserOptions.setDefaultOperationParserOptions(defaultOperationOptions)
ParserOptions.setDefaultSdlParserOptions(defaultSdlOptions)
}
Copy link
Member Author

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)
}
Copy link
Member Author

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)
Copy link
Member Author

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
}

Copy link
Member Author

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

Copy link
Member

@andimarek andimarek left a 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
Copy link
Member

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?

Copy link
Member Author

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

@bbakerman bbakerman added this pull request to the merge queue Mar 20, 2023
@bbakerman bbakerman merged commit 80e3135 into master Mar 20, 2023
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
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.

6 participants