Skip to content

Commit

Permalink
Fixes Issue 28593: loki:fuzz_parse_expr: Timeout in fuzz_parse_expr. (#…
Browse files Browse the repository at this point in the history
…3470)

This was caused by a lot of allocations when parsing range duration.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
  • Loading branch information
cyriltovena authored Mar 12, 2021
1 parent e29d536 commit c49e807
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/logql/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ var functionTokens = map[string]int{

type lexer struct {
scanner.Scanner
errs []ParseError
errs []ParseError
builder strings.Builder
}

func (l *lexer) Lex(lval *exprSymType) int {
Expand Down Expand Up @@ -149,18 +150,18 @@ func (l *lexer) Lex(lval *exprSymType) int {

// scanning duration tokens
if r == '[' {
d := ""
l.builder.Reset()
for r := l.Next(); r != scanner.EOF; r = l.Next() {
if string(r) == "]" {
i, err := model.ParseDuration(d)
if r == ']' {
i, err := model.ParseDuration(l.builder.String())
if err != nil {
l.Error(err.Error())
return 0
}
lval.duration = time.Duration(i)
return RANGE
}
d += string(r)
_, _ = l.builder.WriteRune(r)
}
l.Error("missing closing ']' in duration")
return 0
Expand Down

0 comments on commit c49e807

Please sign in to comment.