Skip to content

Commit

Permalink
Merge pull request #37 from fcharlie/patch-1
Browse files Browse the repository at this point in the history
Fix decoding panic caused by commit with invalid continuation line before extra headers.
  • Loading branch information
chrisd8088 authored Aug 8, 2024
2 parents b805ee7 + cf05f2b commit e2a3f83
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (c *Commit) Decode(hash hash.Hash, from io.Reader, size int64) (n int, err
c.Committer = ""
}
default:
if strings.HasPrefix(s.Text(), " ") {
if strings.HasPrefix(text, " ") && len(c.ExtraHeaders) > 0 {
idx := len(c.ExtraHeaders) - 1
hdr := c.ExtraHeaders[idx]

Expand Down
14 changes: 14 additions & 0 deletions commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,17 @@ func TestCommitEqualReturnsTrueWhenBothCommitsAreNil(t *testing.T) {

assert.True(t, c1.Equal(c2))
}

func TestCommitInvalidMultilineNonExtraHeader(t *testing.T) {
cc := `tree 2aedfd35087c75d17bdbaf4dd56069d44fc75b71
parent 75158117eb8efe60453f8c077527ac3530c81e38
author Jane Doe <[email protected]> 1503956287 -0400
committer Jane Doe <[email protected]> 1503956287 -0400
foo bar
initial commit`

var c Commit
_, err := c.Decode(sha1.New(), strings.NewReader(cc), int64(len(cc)))
assert.NoError(t, err)
}

0 comments on commit e2a3f83

Please sign in to comment.