Skip to content

Commit b6a9011

Browse files
authored
Fix out-of-bounds panic parsing timestamps (#28)
Found by go-fuzz.
1 parent 53bcdf7 commit b6a9011

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

gitdiff/file_header.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ func hasEpochTimestamp(s string) bool {
527527

528528
// a valid timestamp can have optional ':' in zone specifier
529529
// remove that if it exists so we have a single format
530-
if ts[len(ts)-3] == ':' {
530+
if len(ts) >= 3 && ts[len(ts)-3] == ':' {
531531
ts = ts[:len(ts)-3] + ts[len(ts)-2:]
532532
}
533533

gitdiff/file_header_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,14 @@ func TestHasEpochTimestamp(t *testing.T) {
724724
Input: "+++ file.txt\t2019-03-21 12:34:56.789 -0700\n",
725725
Output: false,
726726
},
727+
"notTimestamp": {
728+
Input: "+++ file.txt\trandom text\n",
729+
Output: false,
730+
},
731+
"notTimestampShort": {
732+
Input: "+++ file.txt\t0\n",
733+
Output: false,
734+
},
727735
}
728736

729737
for name, test := range tests {

0 commit comments

Comments
 (0)