Skip to content

Commit e2a3f83

Browse files
authored
Merge pull request git-lfs#37 from fcharlie/patch-1
Fix decoding panic caused by commit with invalid continuation line before extra headers.
2 parents b805ee7 + cf05f2b commit e2a3f83

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

commit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (c *Commit) Decode(hash hash.Hash, from io.Reader, size int64) (n int, err
145145
c.Committer = ""
146146
}
147147
default:
148-
if strings.HasPrefix(s.Text(), " ") {
148+
if strings.HasPrefix(text, " ") && len(c.ExtraHeaders) > 0 {
149149
idx := len(c.ExtraHeaders) - 1
150150
hdr := c.ExtraHeaders[idx]
151151

commit_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,17 @@ func TestCommitEqualReturnsTrueWhenBothCommitsAreNil(t *testing.T) {
455455

456456
assert.True(t, c1.Equal(c2))
457457
}
458+
459+
func TestCommitInvalidMultilineNonExtraHeader(t *testing.T) {
460+
cc := `tree 2aedfd35087c75d17bdbaf4dd56069d44fc75b71
461+
parent 75158117eb8efe60453f8c077527ac3530c81e38
462+
author Jane Doe <[email protected]> 1503956287 -0400
463+
committer Jane Doe <[email protected]> 1503956287 -0400
464+
foo bar
465+
466+
initial commit`
467+
468+
var c Commit
469+
_, err := c.Decode(sha1.New(), strings.NewReader(cc), int64(len(cc)))
470+
assert.NoError(t, err)
471+
}

0 commit comments

Comments
 (0)