Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: control c3 recursion depth (#16159)

rebelice6801166c384b
diff --git a/backend/plugin/parser/base/c3.go b/backend/plugin/parser/base/c3.go
index 0a158d9d38..8e8c511172 100644
--- a/backend/plugin/parser/base/c3.go
+++ b/backend/plugin/parser/base/c3.go
@@ -6,6 +6,8 @@ import (
"github.com/antlr4-go/antlr/v4"
)
+const maxRecursionDepth = 66
+
// CodeCompletionCore is the core of code completion.
// It only relies on the ANTLR runtime and does not depend on any specific language.
type CodeCompletionCore struct {
@@ -392,6 +394,9 @@ func (c *CodeCompletionCore) CollectCandidates(caretTokenIndex int, context antl
}
func (c *CodeCompletionCore) fetchEndStatus(startState antlr.ATNState, tokenIndex int, indentation string) RuleEndStatus {
+ if len(c.callStack.rules) > maxRecursionDepth {
+ return RuleEndStatus{}
+ }
result := make(RuleEndStatus)
c.followSetsByState.CollectFollowSets(c.parser, startState, c.IgnoredTokens, c.PreferredRules)