parser: don't overflow when parsing bad times (#593)

Fixes #585
This commit is contained in:
Thomas Pelletier
2021-09-09 11:59:37 -04:00
committed by GitHub
parent f34c9c332f
commit fa56f48daf
2 changed files with 11 additions and 0 deletions
+5
View File
@@ -894,6 +894,11 @@ byteLoop:
case c == ' ': case c == ' ':
if !seenSpace && i+1 < len(b) && isDigit(b[i+1]) { if !seenSpace && i+1 < len(b) && isDigit(b[i+1]) {
i += 2 i += 2
// Avoid reaching past the end of the document in case the time
// is malformed. See TestIssue585.
if i >= len(b) {
i--
}
seenSpace = true seenSpace = true
hasTime = true hasTime = true
} else { } else {
+6
View File
@@ -1746,6 +1746,12 @@ func TestIssue588(t *testing.T) {
require.Error(t, err) require.Error(t, err)
} }
func TestIssue585(t *testing.T) {
var v interface{}
err := toml.Unmarshal([]byte(`a=1979-05127T 0`), &v)
require.Error(t, err)
}
//nolint:funlen //nolint:funlen
func TestUnmarshalDecodeErrors(t *testing.T) { func TestUnmarshalDecodeErrors(t *testing.T) {
examples := []struct { examples := []struct {