promql: fuzz test needs symbol table for parser

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2023-11-29 18:19:48 +00:00
parent 5f50d974c9
commit 0347148628
1 changed files with 5 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import (
"errors" "errors"
"io" "io"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/textparse" "github.com/prometheus/prometheus/model/textparse"
"github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/promql/parser"
) )
@ -56,8 +57,11 @@ const (
maxInputSize = 10240 maxInputSize = 10240
) )
// Use package-scope symbol table to avoid memory allocation on every fuzzing operation.
var symbolTable = labels.NewSymbolTable()
func fuzzParseMetricWithContentType(in []byte, contentType string) int { func fuzzParseMetricWithContentType(in []byte, contentType string) int {
p, warning := textparse.New(in, contentType, false) p, warning := textparse.New(in, contentType, false, symbolTable)
if warning != nil { if warning != nil {
// An invalid content type is being passed, which should not happen // An invalid content type is being passed, which should not happen
// in this context. // in this context.