Skip to content

Commit b4177b8

Browse files
josephvusichjvusich
authored and
jvusich
committed
plumbing: format: pktline, Accept oversized pkt-lines up to 65524 bytes
The canonical Git client successfully decodes sideband packets up to 65524 bytes in length (4-byte header + 65520-byte payload). The Git protocol documentation was updated in August 2016 to reduce the maximum payload size to 65516 bytes, however old implementations still exist in the wild emitting 65520-byte payloads. As there is no technical difficulty with accepting (not emitting) larger payload sizes, this change adjusts the limit check to allow successful decoding of packets up to 65524 bytes. This change increases compatibility with the current canonical Git implementation. Doc changes from August 2016: git/git@7841c48#diff-52695c8fe91b78b70cea44562ae28297L67 Current packet buffer size is still LARGE_PACKET_MAX (+1 null): https://github.com/git/git/blob/468165c1d8a442994a825f3684528361727cd8c0/sideband.c#L24 https://github.com/git/git/blob/468165c1d8a442994a825f3684528361727cd8c0/sideband.c#L36 LARGE_PACKET_MAX definition: https://github.com/git/git/blob/468165c1d8a442994a825f3684528361727cd8c0/pkt-line.h#L100 Signed-off-by: Joseph Vusich <[email protected]>
1 parent 2cbff8d commit b4177b8

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

plumbing/format/pktline/encoder.go

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type Encoder struct {
1717
const (
1818
// MaxPayloadSize is the maximum payload size of a pkt-line in bytes.
1919
MaxPayloadSize = 65516
20+
21+
// For compatibility with canonical Git implementation, accept longer pkt-lines
22+
OversizePayloadMax = 65520
2023
)
2124

2225
var (

plumbing/format/pktline/scanner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (s *Scanner) readPayloadLen() (int, error) {
9797
return 0, nil
9898
case n <= lenSize:
9999
return 0, ErrInvalidPktLen
100-
case n > MaxPayloadSize+lenSize:
100+
case n > OversizePayloadMax+lenSize:
101101
return 0, ErrInvalidPktLen
102102
default:
103103
return n - lenSize, nil

plumbing/format/pktline/scanner_test.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (s *SuiteScanner) TestInvalid(c *C) {
2020
for _, test := range [...]string{
2121
"0001", "0002", "0003", "0004",
2222
"0001asdfsadf", "0004foo",
23-
"fff1", "fff2",
23+
"fff5", "ffff",
2424
"gorka",
2525
"0", "003",
2626
" 5a", "5 a", "5 \n",
@@ -34,6 +34,20 @@ func (s *SuiteScanner) TestInvalid(c *C) {
3434
}
3535
}
3636

37+
func (s *SuiteScanner) TestDecodeOversizePktLines(c *C) {
38+
for _, test := range [...]string{
39+
"fff1" + strings.Repeat("a", 0xfff1),
40+
"fff2" + strings.Repeat("a", 0xfff2),
41+
"fff3" + strings.Repeat("a", 0xfff3),
42+
"fff4" + strings.Repeat("a", 0xfff4),
43+
} {
44+
r := strings.NewReader(test)
45+
sc := pktline.NewScanner(r)
46+
_ = sc.Scan()
47+
c.Assert(sc.Err(), IsNil)
48+
}
49+
}
50+
3751
func (s *SuiteScanner) TestEmptyReader(c *C) {
3852
r := strings.NewReader("")
3953
sc := pktline.NewScanner(r)

0 commit comments

Comments
 (0)