Set parser recursion limit for fuzz tests. (#8673)

Very large inputs that generate large ASTs can cause some of the
sanitizers to timeout. Setting a smaller complexity limit should help
filter out those cases.

Co-authored-by: jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>
This commit is contained in:
Jonathan Tatum 2022-10-06 08:27:56 -07:00 committed by GitHub
parent 820e17343c
commit a442ef149d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -1,7 +1,7 @@
package cel
func FuzzCompile(data []byte) int {
env, err := NewEnv()
env, err := getCELFuzzEnv()
if err != nil {
panic("impossible to create env")
}

View File

@ -0,0 +1,8 @@
package cel
// Create environment for running under Address sanitizer without timing out.
func getCELFuzzEnv() (*Env, error) {
// Very dense expressions (balanced trees) can cause address sanitizer to
// timeout even though they typically fail in under a second uninstrumented.
return NewEnv(ParserRecursionLimit(60))
}

View File

@ -18,7 +18,12 @@ func FuzzEval(data []byte) int {
for k, _ := range gen.Inputs {
declares = append(declares, decls.NewVar(k, decls.String))
}
env, err := NewEnv(Declarations(declares...))
env, err := getCELFuzzEnv()
if err != nil {
panic("impossible to create env")
}
env, err = env.Extend(Declarations(declares...))
if err != nil {
panic("impossible to create env")
}