Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions plumbing/format/pktline/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ func (s *Scanner) Bytes() []byte {
// pkt-len and substracting the pkt-len size.
func (s *Scanner) readPayloadLen() (int, error) {
if _, err := io.ReadFull(s.r, s.len[:]); err != nil {
if err == io.EOF {
return 0, err
if err == io.ErrUnexpectedEOF {
return 0, ErrInvalidPktLen
}
return 0, ErrInvalidPktLen

return 0, err
}

n, err := hexDecode(s.len)
Expand Down
11 changes: 11 additions & 0 deletions plumbing/format/pktline/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pktline_test

import (
"bytes"
"errors"
"fmt"
"io"
"strings"
Expand Down Expand Up @@ -145,6 +146,16 @@ func (s *SuiteScanner) TestEOF(c *C) {
c.Assert(sc.Err(), IsNil)
}

type mockReader struct{}

func (r *mockReader) Read([]byte) (int, error) { return 0, errors.New("foo") }

func (s *SuiteScanner) TestInternalReadError(c *C) {
sc := pktline.NewScanner(&mockReader{})
c.Assert(sc.Scan(), Equals, false)
c.Assert(sc.Err(), ErrorMatches, "foo")
}

// A section are several non flush-pkt lines followed by a flush-pkt, which
// how the git protocol sends long messages.
func (s *SuiteScanner) TestReadSomeSections(c *C) {
Expand Down