MCPcopy Create free account
hub / github.com/cel-expr/cel-go / ExceedsDepth

Function ExceedsDepth

common/ast/navigable.go:191–205  ·  view source on GitHub ↗

ExceedsDepth determines whether the AST contains expressions nested deeper than the specified maxDepth. The root expression has depth 0, so a maxDepth of 250 permits expressions nested up to and including 250 levels deep. The traversal is bounded: it descends at most maxDepth+1 levels, so it remain

(a *AST, maxDepth int)

Source from the content-addressed store, hash-verified

189// adversarially deep inputs that could otherwise exhaust the Go stack during later checking or
190// planning. A non-positive maxDepth disables the check and returns false.
191func ExceedsDepth(a *AST, maxDepth int) bool {
192 if a == nil || maxDepth <= 0 {
193 return false
194 }
195 exceedsDepth := false
196 visitor := NewExprVisitor(func(e Expr) {
197 if nav, ok := e.(NavigableExpr); ok && nav.Depth() >= maxDepth {
198 exceedsDepth = true
199 }
200 })
201 // Bound the walk to maxDepth+1 levels so it never recurses past the first level that exceeds
202 // the limit, keeping the check itself safe on the deep inputs it guards against.
203 visit(NavigateAST(a), visitor, postOrder, 0, maxDepth+1)
204 return exceedsDepth
205}
206
207type visitOrder int
208

Callers 4

checkLoadedASTDepthFunction · 0.92
TestExceedsDepthFunction · 0.92

Calls 4

NewExprVisitorFunction · 0.85
NavigateASTFunction · 0.85
visitFunction · 0.70
DepthMethod · 0.65

Tested by 3

TestExceedsDepthFunction · 0.74