Skip to content
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

Merged
merged 3 commits into from
Mar 16, 2017

Conversation

bwplotka
Copy link
Member

This led to unexpected results on wrong query with (...)&start=148966367200.372&end=1489667272.372 fields. (additional 00 at the end of start)
That query is wrong because now start > end, but actually internal int64 overflow caused start to be something around MinInt64 (huge negative number) and was passing the end.Before(start) validation.

In my opinion it should return error on API.

Changes:

  • Added int64 overflow validation inside ParseTime and ParseDuration, stictly on ParseFloat path.
  • Added mentioned values as test cases for endpoint, ParseTime and ParseDuration tests

Any feedback welcome!
@brian-brazil @fabxc

BTW: Not sure if negative timestamp makes sense even.. But model.Earliest is actually MinInt64 (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

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>
@@ -243,6 +243,17 @@ func TestEndpoints(t *testing.T) {
},
errType: errorBadData,
},
// Start overflows int64 internally
Copy link
Member

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.

@juliusv
Copy link
Member

juliusv commented Mar 16, 2017

Thanks, looks good besides nit.

Can someone explain me why Prometheus time model supports negative timestamps?

Negative timestamps simply indicate times before Jan 1, 1970.

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)
Copy link
Member

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 >=?

Copy link
Member Author

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 (:

Copy link
Member Author

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>
@juliusv
Copy link
Member

juliusv commented Mar 16, 2017

👍 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants