diff --git a/plumbing/format/pktline/encoder.go b/plumbing/format/pktline/encoder.go index eae85cc4a..6d409795b 100644 --- a/plumbing/format/pktline/encoder.go +++ b/plumbing/format/pktline/encoder.go @@ -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 ( diff --git a/plumbing/format/pktline/scanner.go b/plumbing/format/pktline/scanner.go index 4af254f00..99aab46e8 100644 --- a/plumbing/format/pktline/scanner.go +++ b/plumbing/format/pktline/scanner.go @@ -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 diff --git a/plumbing/format/pktline/scanner_test.go b/plumbing/format/pktline/scanner_test.go index 048ea3829..9660c2d48 100644 --- a/plumbing/format/pktline/scanner_test.go +++ b/plumbing/format/pktline/scanner_test.go @@ -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", @@ -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)