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_test.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_test.go')
-rw-r--r-- | plumbing/object/commit_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/plumbing/object/commit_test.go b/plumbing/object/commit_test.go index b5dfbe3..e72b703 100644 --- a/plumbing/object/commit_test.go +++ b/plumbing/object/commit_test.go @@ -325,6 +325,22 @@ RUysgqjcpT8+iQM1PblGfHR4XAhuOqN5Fx06PSaFZhqvWFezJ28/CLyX5q+oIVk= c.Assert(err, IsNil) c.Assert(decoded.PGPSignature, Equals, pgpsignature) + // signature with extra empty line, it caused "index out of range" when + // parsing it + + pgpsignature2 := "\n" + pgpsignature + + commit.PGPSignature = pgpsignature2 + encoded = &plumbing.MemoryObject{} + decoded = &Commit{} + + err = commit.Encode(encoded) + c.Assert(err, IsNil) + + err = decoded.Decode(encoded) + c.Assert(err, IsNil) + c.Assert(decoded.PGPSignature, Equals, pgpsignature2) + // signature in author name commit.PGPSignature = "" @@ -461,3 +477,21 @@ func (s *SuiteCommit) TestPatchCancel(c *C) { c.Assert(err, ErrorMatches, "operation canceled") } + +func (s *SuiteCommit) TestMalformedHeader(c *C) { + encoded := &plumbing.MemoryObject{} + decoded := &Commit{} + commit := *s.Commit + + commit.PGPSignature = "\n" + commit.Author.Name = "\n" + commit.Author.Email = "\n" + commit.Committer.Name = "\n" + commit.Committer.Email = "\n" + + err := commit.Encode(encoded) + c.Assert(err, IsNil) + + err = decoded.Decode(encoded) + c.Assert(err, IsNil) +} |