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

Decoder: check for invalid characters in timezone #695

Merged
merged 1 commit into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,15 @@ func parseDateTime(b []byte) (time.Time, error) {
return time.Time{}, newDecodeError(b[3:4], "expected a : separator")
}

hours := digitsToInt(b[1:3])
minutes := digitsToInt(b[4:6])
hours, err := parseDecimalDigits(b[1:3])
if err != nil {
return time.Time{}, err
}
minutes, err := parseDecimalDigits(b[4:6])
if err != nil {
return time.Time{}, err
}

seconds := direction * (hours*3600 + minutes*60)
zone = time.FixedZone("", seconds)
b = b[dateTimeByteLen:]
Expand Down
12 changes: 0 additions & 12 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,18 +886,6 @@ func (p *parser) parseIntOrFloatOrDateTime(b []byte) (ast.Reference, []byte, err
return p.scanIntOrFloat(b)
}

func digitsToInt(b []byte) int {
x := 0

for _, d := range b {
x *= 10
x += int(d - '0')
}

return x
}

//nolint:gocognit,cyclop
func (p *parser) scanDateTime(b []byte) (ast.Reference, []byte, error) {
// scans for contiguous characters in [0-9T:Z.+-], and up to one space if
// followed by a digit.
Expand Down
8 changes: 8 additions & 0 deletions unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2632,6 +2632,14 @@ world'`,
desc: `invalid number of seconds digits with trailing digit`,
data: `a=0000-01-01 00:00:000000Z3`,
},
{
desc: `invalid character in zone offset hours`,
data: `a=0000-01-01 00:00:00+0Z:00`,
},
{
desc: `invalid character in zone offset minutes`,
data: `a=0000-01-01 00:00:00+00:0Z`,
},
{
desc: `invalid number of seconds`,
data: `a=0000-01-01 00:00:00+27000`,
Expand Down