Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #856 from kuba--/fix-840/corrupted-objects
Browse files Browse the repository at this point in the history
plumbing: packfile, Don't copy empty objects. Fixes #840
  • Loading branch information
mcuadros authored Jun 8, 2018
2 parents a8a12e0 + 88f0dc3 commit b235700
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions plumbing/format/packfile/delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
}}
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion plumbing/format/packfile/diff_delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b235700

Please sign in to comment.