Skip to content

Commit

Permalink
utils.go: fix index out of range panic when too small number of arg…
Browse files Browse the repository at this point in the history
…s is passed to rollup function inside the query at IsLikelyInvalid()
  • Loading branch information
valyala committed Dec 5, 2024
1 parent e168a92 commit 788d984
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func IsLikelyInvalid(e Expr) bool {
return
}
idx := GetRollupArgIdx(fe)
if idx < 0 {
if idx < 0 || idx >= len(fe.Args) {
return
}
arg := fe.Args[idx]
Expand Down
3 changes: 3 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ func TestIsLikelyInvalid(t *testing.T) {
f(`rate(rate(foo))`, true)
f(`1 + rate(label_set(foo, "bar", "baz"))`, true)
f(`rate(sum(foo) offset 5m)`, true)

// invalid number of args
f(`quantile_over_time(foo)`, false)
}

func TestIsSupportedFunction(t *testing.T) {
Expand Down

0 comments on commit 788d984

Please sign in to comment.