PromQL duration expr: Add a check for durations our of range

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
This commit is contained in:
Julien Pivotto 2025-03-24 12:08:06 +01:00
parent 7370d62acf
commit 9cfd6f7df8
2 changed files with 20 additions and 0 deletions

View File

@ -1115,6 +1115,11 @@ func (p *parser) evalDurationExprBinOp(lhs, rhs Node, op Item) *NumberLiteral {
return &NumberLiteral{Val: 0}
}
if val > 1<<63/1e9 || val < -(1<<63)/1e9 {
p.addParseErrf(op.PositionRange(), "duration out of range")
return &NumberLiteral{Val: 0}
}
return &NumberLiteral{
Val: val,
PosRange: posrange.PositionRange{

View File

@ -4060,6 +4060,21 @@ var testExpr = []struct {
fail: true,
errMsg: `modulo by zero`,
},
{
input: `foo[150y+150y]`,
fail: true,
errMsg: `duration out of range`,
},
{
input: `foo offset (150y+150y)`,
fail: true,
errMsg: `duration out of range`,
},
{
input: `foo offset (-2*150y)`,
fail: true,
errMsg: `duration out of range`,
},
}
func makeInt64Pointer(val int64) *int64 {