-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
topdown: Fixing nanos int overflow issue for time.* built-in functions (
#4117) * topdown: Fixing nanos int overflow issue for time.* built-in functions The go Time.UnixNano() function result is undefined for dates that cannot fit into an int64 when converted to Unix time in nanoseconds. Updating built-in functions to return error if date is too low/high. Fixes: #4098 Signed-off-by: Johan Fylling <johan.dev@fylling.se>
- Loading branch information
1 parent
bbe8afd
commit edf5f25
Showing
6 changed files
with
150 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,50 @@ | ||
cases: | ||
- data: | ||
a: | ||
- 1 | ||
- 2 | ||
- 3 | ||
- 4 | ||
b: | ||
v1: hello | ||
v2: goodbye | ||
c: | ||
- x: | ||
- true | ||
- false | ||
- foo | ||
"y": | ||
- null | ||
- 3.14159 | ||
z: | ||
p: true | ||
q: false | ||
d: | ||
e: | ||
- bar | ||
- baz | ||
f: | ||
- xs: | ||
- 1 | ||
ys: | ||
- 2 | ||
- xs: | ||
- 2 | ||
ys: | ||
- 3 | ||
g: | ||
a: | ||
- 1 | ||
- 0 | ||
- 0 | ||
- 0 | ||
b: | ||
- 0 | ||
- 2 | ||
- 0 | ||
- 0 | ||
c: | ||
- 0 | ||
- 0 | ||
- 0 | ||
- 4 | ||
h: | ||
- - 1 | ||
- 2 | ||
- 3 | ||
- - 2 | ||
- 3 | ||
- 4 | ||
l: | ||
- a: bob | ||
b: -1 | ||
c: | ||
- 1 | ||
- 2 | ||
- 3 | ||
- 4 | ||
- a: alice | ||
b: 1 | ||
c: | ||
- 2 | ||
- 3 | ||
- 4 | ||
- 5 | ||
d: null | ||
m: [] | ||
numbers: | ||
- "1" | ||
- "2" | ||
- "3" | ||
- "4" | ||
strings: | ||
bar: 2 | ||
baz: 3 | ||
foo: 1 | ||
three: 3 | ||
- note: time/parse_nanos | ||
modules: | ||
- | | ||
package generated | ||
p = ns { | ||
time.parse_ns("2006-01-02T15:04:05Z07:00", "2017-06-02T19:00:00-07:00", ns) | ||
p[case_id] = ns { | ||
case := input.cases[case_id] | ||
time.parse_ns(case.layout, case.value, ns) | ||
} | ||
note: time/parse nanos | ||
query: data.generated.p = x | ||
input: { cases: { | ||
1: { layout: "2006-01-02T15:04:05Z07:00", value: "2017-06-02T19:00:00-07:00" }, # RFC3339 | ||
2: { layout: "2006-01-02T15:04:05Z07:00", value: "1677-09-21T00:12:43.145224192-00:00" }, # Earliest valid time | ||
3: { layout: "2006-01-02T15:04:05Z07:00", value: "2262-04-11T23:47:16.854775807-00:00" }, # Latest valid time | ||
4: { layout: "01/02 03:04:05PM '06 -0700", value: "06/02 07:00:00PM '17 -0700" }, # Layout | ||
5: { layout: "02 Jan 06 15:04 -0700", value: "02 Jun 17 19:00 -0700" }, # RFC822Z | ||
}} | ||
want_result: | ||
- x: 1496455200000000000 | ||
- x: { | ||
1: 1496455200000000000, | ||
2: -9223372036854775808, | ||
3: 9223372036854775807, | ||
4: 1496455200000000000, | ||
5: 1496455200000000000 | ||
} | ||
- note: time/parse_nanos_too_small | ||
modules: | ||
- | | ||
package generated | ||
p = ns { | ||
time.parse_ns("2006-01-02T15:04:05Z07:00", "1677-09-21T00:12:43.145224191-00:00", ns) | ||
} | ||
query: data.generated.p = x | ||
strict_error: true | ||
want_error_code: eval_builtin_error | ||
want_error: 'time outside of valid range' | ||
- note: time/parse_nanos_too_large | ||
modules: | ||
- | | ||
package generated | ||
p = ns { | ||
time.parse_ns("2006-01-02T15:04:05Z07:00", "2262-04-11T23:47:16.854775808-00:00", ns) | ||
} | ||
query: data.generated.p = x | ||
strict_error: true | ||
want_error_code: eval_builtin_error | ||
want_error: 'time outside of valid range' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,48 @@ | ||
cases: | ||
- data: | ||
a: | ||
- 1 | ||
- 2 | ||
- 3 | ||
- 4 | ||
b: | ||
v1: hello | ||
v2: goodbye | ||
c: | ||
- x: | ||
- true | ||
- false | ||
- foo | ||
"y": | ||
- null | ||
- 3.14159 | ||
z: | ||
p: true | ||
q: false | ||
d: | ||
e: | ||
- bar | ||
- baz | ||
f: | ||
- xs: | ||
- 1 | ||
ys: | ||
- 2 | ||
- xs: | ||
- 2 | ||
ys: | ||
- 3 | ||
g: | ||
a: | ||
- 1 | ||
- 0 | ||
- 0 | ||
- 0 | ||
b: | ||
- 0 | ||
- 2 | ||
- 0 | ||
- 0 | ||
c: | ||
- 0 | ||
- 0 | ||
- 0 | ||
- 4 | ||
h: | ||
- - 1 | ||
- 2 | ||
- 3 | ||
- - 2 | ||
- 3 | ||
- 4 | ||
l: | ||
- a: bob | ||
b: -1 | ||
c: | ||
- 1 | ||
- 2 | ||
- 3 | ||
- 4 | ||
- a: alice | ||
b: 1 | ||
c: | ||
- 2 | ||
- 3 | ||
- 4 | ||
- 5 | ||
d: null | ||
m: [] | ||
numbers: | ||
- "1" | ||
- "2" | ||
- "3" | ||
- "4" | ||
strings: | ||
bar: 2 | ||
baz: 3 | ||
foo: 1 | ||
three: 3 | ||
- note: time/parse_rfc3339_nanos | ||
modules: | ||
- | | ||
package generated | ||
p = ns { | ||
time.parse_rfc3339_ns("2017-06-02T19:00:00-07:00", ns) | ||
} | ||
note: time/parse rfc3339 nanos | ||
- | | ||
package generated | ||
p[t] = ns { | ||
t = input.cases[_] | ||
time.parse_rfc3339_ns(t, ns) | ||
} | ||
query: data.generated.p = x | ||
input: { cases: [ | ||
"1677-09-21T00:12:43.145224192-00:00", # Earliest valid time | ||
"1970-01-01T00:00:00-00:00", | ||
"2017-06-02T19:00:00-07:00", | ||
"2262-04-11T23:47:16.854775807-00:00" # Latest valid time | ||
]} | ||
want_result: | ||
- x: 1496455200000000000 | ||
- x: { | ||
"1677-09-21T00:12:43.145224192-00:00": -9223372036854775808, | ||
"1970-01-01T00:00:00-00:00": 0, | ||
"2017-06-02T19:00:00-07:00": 1496455200000000000, | ||
"2262-04-11T23:47:16.854775807-00:00": 9223372036854775807, | ||
} | ||
- note: time/parse_rfc3339_nanos_too_small | ||
modules: | ||
- | | ||
package generated | ||
p = ns { | ||
time.parse_rfc3339_ns("1677-09-21T00:12:43.145224191-00:00", ns) | ||
} | ||
query: data.generated.p = x | ||
strict_error: true | ||
want_error_code: eval_builtin_error | ||
want_error: 'time outside of valid range' | ||
- note: time/parse_rfc3339_nanos_too_large | ||
modules: | ||
- | | ||
package generated | ||
p = ns { | ||
time.parse_rfc3339_ns("2262-04-11T23:47:16.854775808-00:00", ns) | ||
} | ||
query: data.generated.p = x | ||
strict_error: true | ||
want_error_code: eval_builtin_error | ||
want_error: 'time outside of valid range' |
Oops, something went wrong.