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

plumbing: format: pktline, Accept oversized pkt-lines up to 65524 bytes #797

Merged
merged 1 commit into from
Apr 3, 2018
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
3 changes: 3 additions & 0 deletions plumbing/format/pktline/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type Encoder struct {
const (
// MaxPayloadSize is the maximum payload size of a pkt-line in bytes.
MaxPayloadSize = 65516

// For compatibility with canonical Git implementation, accept longer pkt-lines
OversizePayloadMax = 65520
)

var (
Expand Down
2 changes: 1 addition & 1 deletion plumbing/format/pktline/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *Scanner) readPayloadLen() (int, error) {
return 0, nil
case n <= lenSize:
return 0, ErrInvalidPktLen
case n > MaxPayloadSize+lenSize:
case n > OversizePayloadMax+lenSize:
return 0, ErrInvalidPktLen
default:
return n - lenSize, nil
Expand Down
16 changes: 15 additions & 1 deletion plumbing/format/pktline/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (s *SuiteScanner) TestInvalid(c *C) {
for _, test := range [...]string{
"0001", "0002", "0003", "0004",
"0001asdfsadf", "0004foo",
"fff1", "fff2",
"fff5", "ffff",
"gorka",
"0", "003",
" 5a", "5 a", "5 \n",
Expand All @@ -34,6 +34,20 @@ func (s *SuiteScanner) TestInvalid(c *C) {
}
}

func (s *SuiteScanner) TestDecodeOversizePktLines(c *C) {
for _, test := range [...]string{
"fff1" + strings.Repeat("a", 0xfff1),
"fff2" + strings.Repeat("a", 0xfff2),
"fff3" + strings.Repeat("a", 0xfff3),
"fff4" + strings.Repeat("a", 0xfff4),
} {
r := strings.NewReader(test)
sc := pktline.NewScanner(r)
_ = sc.Scan()
c.Assert(sc.Err(), IsNil)
}
}

func (s *SuiteScanner) TestEmptyReader(c *C) {
r := strings.NewReader("")
sc := pktline.NewScanner(r)
Expand Down