Skip to content

Commit

Permalink
Detect when a time literal will overflow or underflow the query engine
Browse files Browse the repository at this point in the history
Fixes #3369.
  • Loading branch information
jsternberg committed Apr 13, 2016
1 parent 36ca49c commit 3c7aabc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- [#6271](https://github.com/influxdata/influxdb/issues/6271): Fixed deadlock in tsm1 file store.
- [#6287](https://github.com/influxdata/influxdb/issues/6287): Fix data race in Influx Client.
- [#6252](https://github.com/influxdata/influxdb/pull/6252): Remove TSDB listener accept message @simnv
- [#3369](https://github.com/influxdata/influxdb/issues/3369): Detect when a timer literal will overflow or underflow the query engine.

## v0.12.0 [2016-04-05]
### Release Notes
Expand Down
5 changes: 5 additions & 0 deletions influxql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -3469,6 +3469,11 @@ func timeExprValue(ref Expr, lit Expr) (t time.Time, err error) {
if ref, ok := ref.(*VarRef); ok && strings.ToLower(ref.Val) == "time" {
switch lit := lit.(type) {
case *TimeLiteral:
if lit.Val.After(time.Unix(0, MaxTime)) {
return time.Time{}, fmt.Errorf("time %s overflows time literal", lit.Val.Format(time.RFC3339))
} else if lit.Val.Before(time.Unix(0, MinTime)) {
return time.Time{}, fmt.Errorf("time %s underflows time literal", lit.Val.Format(time.RFC3339))
}
return lit.Val, nil
case *DurationLiteral:
return time.Unix(0, int64(lit.Val)).UTC(), nil
Expand Down
2 changes: 2 additions & 0 deletions influxql/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,8 @@ func TestTimeRange(t *testing.T) {

// Invalid time expressions.
{expr: `time > "2000-01-01 00:00:00"`, min: `0001-01-01T00:00:00Z`, max: `0001-01-01T00:00:00Z`, err: `invalid operation: time and *influxql.VarRef are not compatible`},
{expr: `time > '2262-04-11 13:47:17'`, min: `0001-01-01T00:00:00Z`, max: `0001-01-01T00:00:00Z`, err: `time 2262-04-11T13:47:17Z overflows time literal`},
{expr: `time > '1677-09-20 19:12:43'`, min: `0001-01-01T00:00:00Z`, max: `0001-01-01T00:00:00Z`, err: `time 1677-09-20T19:12:43Z underflows time literal`},
} {
// Extract time range.
expr := MustParseExpr(tt.expr)
Expand Down

0 comments on commit 3c7aabc

Please sign in to comment.