From 0347148628ac5511cc52c26497287b7fb6ce9a76 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 29 Nov 2023 18:19:48 +0000 Subject: [PATCH] promql: fuzz test needs symbol table for parser Signed-off-by: Bryan Boreham --- promql/fuzz.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/promql/fuzz.go b/promql/fuzz.go index d2e5925eb..3fd50b949 100644 --- a/promql/fuzz.go +++ b/promql/fuzz.go @@ -20,6 +20,7 @@ import ( "errors" "io" + "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/textparse" "github.com/prometheus/prometheus/promql/parser" ) @@ -56,8 +57,11 @@ const ( 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 { - p, warning := textparse.New(in, contentType, false) + p, warning := textparse.New(in, contentType, false, symbolTable) if warning != nil { // An invalid content type is being passed, which should not happen // in this context.