diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-06-08 09:32:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-08 09:32:46 +0200 |
commit | b23570073eaee3489e5e3d666f22ba5cbeb53243 (patch) | |
tree | b8bfa26e2215a20810f482ca281cc831ce48e806 /plumbing | |
parent | a8a12e0edc6af6ea44fe8cce76d7b4658d85a50c (diff) | |
parent | 88f0dc3d89a0391f9f52d913207556d15a4c2a77 (diff) | |
download | go-git-b23570073eaee3489e5e3d666f22ba5cbeb53243.tar.gz |
Merge pull request #856 from kuba--/fix-840/corrupted-objectsv4.4.1
plumbing: packfile, Don't copy empty objects. Fixes #840
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/format/packfile/delta_test.go | 21 | ||||
-rw-r--r-- | plumbing/format/packfile/diff_delta.go | 2 |
2 files changed, 19 insertions, 4 deletions
diff --git a/plumbing/format/packfile/delta_test.go b/plumbing/format/packfile/delta_test.go index 42b777a..98f53f6 100644 --- a/plumbing/format/packfile/delta_test.go +++ b/plumbing/format/packfile/delta_test.go @@ -62,7 +62,7 @@ func (s *DeltaSuite) SetUpSuite(c *C) { target: []piece{{"1", 30}, {"2", 20}, {"7", 40}, {"4", 400}, {"5", 10}}, }, { - description: "A copy operation bigger tan 64kb", + description: "A copy operation bigger than 64kb", base: []piece{{bigRandStr, 1}, {"1", 200}}, target: []piece{{bigRandStr, 1}}, }} @@ -72,12 +72,16 @@ var bigRandStr = randStringBytes(100 * 1024) const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" -func randStringBytes(n int) string { +func randBytes(n int) []byte { b := make([]byte, n) for i := range b { b[i] = letterBytes[rand.Intn(len(letterBytes))] } - return string(b) + return b +} + +func randStringBytes(n int) string { + return string(randBytes(n)) } func (s *DeltaSuite) TestAddDelta(c *C) { @@ -110,3 +114,14 @@ func (s *DeltaSuite) TestIncompleteDelta(c *C) { c.Assert(err, NotNil) c.Assert(result, IsNil) } + +func (s *DeltaSuite) TestMaxCopySizeDelta(c *C) { + baseBuf := randBytes(maxCopySize) + targetBuf := baseBuf[0:] + targetBuf = append(targetBuf, byte(1)) + + delta := DiffDelta(baseBuf, targetBuf) + result, err := PatchDelta(baseBuf, delta) + c.Assert(err, IsNil) + c.Assert(result, DeepEquals, targetBuf) +} diff --git a/plumbing/format/packfile/diff_delta.go b/plumbing/format/packfile/diff_delta.go index 4d56dc1..d35e78a 100644 --- a/plumbing/format/packfile/diff_delta.go +++ b/plumbing/format/packfile/diff_delta.go @@ -111,7 +111,7 @@ func diffDelta(index *deltaIndex, src []byte, tgt []byte) []byte { rl := l aOffset := offset - for { + for rl > 0 { if rl < maxCopySize { buf.Write(encodeCopyOperation(aOffset, rl)) break |