Restrict max-memory to Extract() calls only

This commit is contained in:
Ben Johnson 2022-02-09 14:05:57 -07:00 • committed by Matthew Jaffee
parent 4fb22e495c
commit 6d06f5550b
2 changed files with 25 additions and 1 deletions

View file

@ -257,7 +257,7 @@ func (e *executor) Execute(ctx context.Context, index string, q *pql.Query, shar
opt = &execOptions{}
}
// Default maximum memory, if not passed in.
if opt.MaxMemory == 0 {
if opt.MaxMemory == 0 && q.HasCall("Extract") {
opt.MaxMemory = e.maxMemory
}

View file

@ -35,6 +35,16 @@ func (q *Query) ExpandVars(vars map[string]interface{}) (*Query, error) {
return &other, nil
}
// HasCall returns true if q contains the given call name.
func (q *Query) HasCall(name string) bool {
for _, c := range q.Calls {
if c.HasCall(name) {
return true
}
}
return false
}
func (q *Query) startCall(name string) {
// Coerce every name into a canonical form if we know of one.
if canon, ok := canonicalCaps[strings.ToLower(name)]; ok {
@ -349,6 +359,20 @@ type Call struct {
Precomputed map[uint64]interface{}
}
// HasCall returns true if q contains the given call name.
func (c *Call) HasCall(name string) bool {
if c.Name == name {
return true
}
for _, child := range c.Children {
if child.HasCall(name) {
return true
}
}
return false
}
// callInfo defines the arguments allowed for a particular PQL call, and
// possibly things about its semantics. If allowUnknown is true, unfamiliar
// non-reserved names are allowed on the assumption that they're field names.