diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-08-21 10:35:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-21 10:35:26 +0200 |
commit | 8120de80b2344a8a4dd63c8cc3bf564e390f989c (patch) | |
tree | f814fbc649c3e02df534b45635e684ff8a84a992 /plumbing/object/commit.go | |
parent | 1cef577576855d92ca4a3b23e205d08b3dac9027 (diff) | |
parent | 166623633e285e17b0582443c9d03b842b6370fa (diff) | |
download | go-git-8120de80b2344a8a4dd63c8cc3bf564e390f989c.tar.gz |
Merge pull request #921 from jfontan/fix/empty-headers
plumbing/object: fix panic when reading object header
Diffstat (limited to 'plumbing/object/commit.go')
-rw-r--r-- | plumbing/object/commit.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/plumbing/object/commit.go b/plumbing/object/commit.go index 00ae3f1..e254342 100644 --- a/plumbing/object/commit.go +++ b/plumbing/object/commit.go @@ -199,17 +199,23 @@ func (c *Commit) Decode(o plumbing.EncodedObject) (err error) { } split := bytes.SplitN(line, []byte{' '}, 2) + + var data []byte + if len(split) == 2 { + data = split[1] + } + switch string(split[0]) { case "tree": - c.TreeHash = plumbing.NewHash(string(split[1])) + c.TreeHash = plumbing.NewHash(string(data)) case "parent": - c.ParentHashes = append(c.ParentHashes, plumbing.NewHash(string(split[1]))) + c.ParentHashes = append(c.ParentHashes, plumbing.NewHash(string(data))) case "author": - c.Author.Decode(split[1]) + c.Author.Decode(data) case "committer": - c.Committer.Decode(split[1]) + c.Committer.Decode(data) case headerpgp: - c.PGPSignature += string(split[1]) + "\n" + c.PGPSignature += string(data) + "\n" pgpsig = true } } else { |