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

Commit 6b79be5

Browse files
authored
format/pktline: fix readPayloadLen err handling (#148)
1 parent a7335e5 commit 6b79be5

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

plumbing/format/pktline/scanner.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ func (s *Scanner) Bytes() []byte {
8080
// pkt-len and substracting the pkt-len size.
8181
func (s *Scanner) readPayloadLen() (int, error) {
8282
if _, err := io.ReadFull(s.r, s.len[:]); err != nil {
83-
if err == io.EOF {
84-
return 0, err
83+
if err == io.ErrUnexpectedEOF {
84+
return 0, ErrInvalidPktLen
8585
}
86-
return 0, ErrInvalidPktLen
86+
87+
return 0, err
8788
}
8889

8990
n, err := hexDecode(s.len)

plumbing/format/pktline/scanner_test.go

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

33
import (
44
"bytes"
5+
"errors"
56
"fmt"
67
"io"
78
"strings"
@@ -145,6 +146,16 @@ func (s *SuiteScanner) TestEOF(c *C) {
145146
c.Assert(sc.Err(), IsNil)
146147
}
147148

149+
type mockReader struct{}
150+
151+
func (r *mockReader) Read([]byte) (int, error) { return 0, errors.New("foo") }
152+
153+
func (s *SuiteScanner) TestInternalReadError(c *C) {
154+
sc := pktline.NewScanner(&mockReader{})
155+
c.Assert(sc.Scan(), Equals, false)
156+
c.Assert(sc.Err(), ErrorMatches, "foo")
157+
}
158+
148159
// A section are several non flush-pkt lines followed by a flush-pkt, which
149160
// how the git protocol sends long messages.
150161
func (s *SuiteScanner) TestReadSomeSections(c *C) {

0 commit comments

Comments
 (0)