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

Commit 4c89741

Browse files
committed
fix zlib invalid header error
The return value of reads to the packfile were being ignored, so zlib was getting invalid data on it read buffers.
1 parent f39e08f commit 4c89741

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

formats/packfile/reader.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (r *Reader) Read(s core.ObjectStorage) (int64, error) {
9898

9999
func (r *Reader) validateHeader() error {
100100
var header = make([]byte, 4)
101-
if _, err := r.r.Read(header); err != nil {
101+
if _, err := io.ReadFull(r.r, header); err != nil {
102102
return err
103103
}
104104

@@ -127,7 +127,6 @@ func (r *Reader) readObjects(count uint32) error {
127127
start := r.r.position
128128
obj, err := r.newRAWObject()
129129
if err != nil && err != io.EOF {
130-
fmt.Println(err)
131130
return err
132131
}
133132

@@ -188,7 +187,7 @@ func (r *Reader) newRAWObject() (core.Object, error) {
188187

189188
func (r *Reader) readREFDelta(raw core.Object) error {
190189
var ref core.Hash
191-
if _, err := r.r.Read(ref[:]); err != nil {
190+
if _, err := io.ReadFull(r.r, ref[:]); err != nil {
192191
return err
193192
}
194193

tree_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package git
22

33
import (
44
"os"
5+
"sort"
56

67
"gopkg.in/src-d/go-git.v2/core"
78
"gopkg.in/src-d/go-git.v2/formats/packfile"
@@ -26,6 +27,7 @@ func (s *SuiteTree) SetUpSuite(c *C) {
2627
{"https://github.com/jamesob/desk.git", "formats/packfile/fixtures/jamesob-desk.pack"},
2728
{"https://github.com/spinnaker/spinnaker.git", "formats/packfile/fixtures/spinnaker-spinnaker.pack"},
2829
{"https://github.com/alcortesm/binary-relations.git", "formats/packfile/fixtures/alcortesm-binary-relations.pack"},
30+
{"https://github.com/Tribler/dispersy.git", "formats/packfile/fixtures/tribler-dispersy.pack"},
2931
}
3032
s.repos = make(map[string]*Repository, 0)
3133
for _, fixRepo := range fixtureRepos {
@@ -132,3 +134,69 @@ func (s *SuiteTree) TestFile(c *C) {
132134
}
133135
}
134136
}
137+
138+
func (s *SuiteTree) TestFiles(c *C) {
139+
for i, t := range []struct {
140+
repo string // the repo name as in localRepos
141+
commit string // the commit to search for the file
142+
files []string // the expected files in the commit
143+
}{
144+
{"https://github.com/alcortesm/binary-relations.git", "b373f85fa2594d7dcd9989f4a5858a81647fb8ea", []string{
145+
"binary-relations.tex",
146+
".gitignore",
147+
"imgs-gen/simple-graph/fig.fig",
148+
"imgs-gen/simple-graph/Makefile",
149+
"Makefile",
150+
"src/map-slice/map-slice.go",
151+
"src/simple-arrays/simple-arrays.go",
152+
}},
153+
{"https://github.com/Tribler/dispersy.git", "f5a1fca709f760bf75a7adaa480bf0f0e1a547ee", []string{
154+
"authentication.py",
155+
"bloomfilter.py",
156+
"bootstrap.py",
157+
"cache.py",
158+
"callback.py",
159+
"candidate.py",
160+
"community.py",
161+
"conversion.py",
162+
"crypto.py",
163+
"database.py",
164+
"debugcommunity.py",
165+
"debug.py",
166+
"decorator.py",
167+
"destination.py",
168+
"dispersydatabase.py",
169+
"dispersy.py",
170+
"distribution.py",
171+
"dprint.py",
172+
"encoding.py",
173+
"endpoint.py",
174+
"__init__.py",
175+
"member.py",
176+
"message.py",
177+
"meta.py",
178+
"payload.py",
179+
"requestcache.py",
180+
"resolution.py",
181+
"script.py",
182+
"singleton.py",
183+
"timeline.py",
184+
"tool/callbackscript.py",
185+
"tool/__init__.py",
186+
"tool/scenarioscript.py",
187+
}},
188+
{"https://github.com/Tribler/dispersy.git", "9d38ff85ca03adcf68dc14f5b68b8994f15229f4", []string(nil)},
189+
} {
190+
commit, err := s.repos[t.repo].Commit(core.NewHash(t.commit))
191+
c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit))
192+
193+
tree := commit.Tree()
194+
var output []string
195+
for file := range tree.Files() {
196+
output = append(output, file.Name)
197+
}
198+
sort.Strings(output)
199+
sort.Strings(t.files)
200+
c.Assert(output, DeepEquals, t.files, Commentf("subtest %d, repo=%s, commit=%s", i, t.repo, t.commit))
201+
}
202+
}

0 commit comments

Comments
 (0)