Fix out-of-bounds panic parsing timestamps (#28)

Found by go-fuzz.
This commit is contained in:
Billy Keyes
2021-09-09 14:24:16 -04:00
committed by GitHub
parent 53bcdf7e5d
commit b6a90110a3
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -527,7 +527,7 @@ func hasEpochTimestamp(s string) bool {
// a valid timestamp can have optional ':' in zone specifier
// remove that if it exists so we have a single format
if ts[len(ts)-3] == ':' {
if len(ts) >= 3 && ts[len(ts)-3] == ':' {
ts = ts[:len(ts)-3] + ts[len(ts)-2:]
}
+8
View File
@@ -724,6 +724,14 @@ func TestHasEpochTimestamp(t *testing.T) {
Input: "+++ file.txt\t2019-03-21 12:34:56.789 -0700\n",
Output: false,
},
"notTimestamp": {
Input: "+++ file.txt\trandom text\n",
Output: false,
},
"notTimestampShort": {
Input: "+++ file.txt\t0\n",
Output: false,
},
}
for name, test := range tests {