-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed int64 overflow for timestamp in v1/api parseDuration and parseTime #2501
Conversation
This led to unexpected results on wrong query with "(...)&start=148966367200.372&end=1489667272.372" That query is wrong because of `start > end` but actually internal int64 overflow caused start to be something around MinInt64 (huge negative value) and was passing validation. BTW: Not sure if negative timestamp makes sense even.. But model.Earliest is actually MinInt64, can someone explain me why? Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
web/api/v1/api_test.go
Outdated
@@ -243,6 +243,17 @@ func TestEndpoints(t *testing.T) { | |||
}, | |||
errType: errorBadData, | |||
}, | |||
// Start overflows int64 internally |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
End all comments with period please.
Thanks, looks good besides nit.
Negative timestamps simply indicate times before Jan 1, 1970. |
web/api/v1/api.go
Outdated
return model.TimeFromUnixNano(ts), nil | ||
ts := t * float64(time.Second) | ||
if ts >= float64(math.MaxInt64) || ts <= float64(math.MinInt64) { | ||
return 0, fmt.Errorf("cannot parse %q to a valid timestamp. It overflows int64", s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be <
and >
and not <=
and >=
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does not make any difference, but I agree that it will be never equal (:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, you are right, it makes difference (: My bad. No error should happen on equal....
Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
👍 Thanks! |
This led to unexpected results on wrong query with
(...)&start=148966367200.372&end=1489667272.372
fields. (additional00
at the end of start)That query is wrong because now
start > end
, but actually internal int64 overflow caused start to be something aroundMinInt64
(huge negative number) and was passing theend.Before(start)
validation.In my opinion it should return error on API.
Changes:
ParseTime
andParseDuration
, stictly onParseFloat
path.Any feedback welcome!
@brian-brazil @fabxc
BTW: Not sure if negative timestamp makes sense even.. But
model.Earliest
is actuallyMinInt64
(https://github.com/prometheus/common/blob/master/model/time.go#L36)Can someone explain me why Prometheus time model supports negative timestamps?
Signed-off-by: Bartek Plotka bwplotka@gmail.com