aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorJoseph Vusich <jvusich@amazon.com>2018-04-02 21:31:40 +0000
committerjvusich <jvusich@users.noreply.github.com>2018-04-02 23:36:59 -0700
commitb4177b89c08b3cd7c791f223b4828b4a81a62312 (patch)
treed75d3fb55548d3cdbd87cc7e5c7cbe5d1baa3b8d /plumbing
parent2cbff8d8ffa42dd1b399b3c94d094bdb2d1cdf5c (diff)
downloadgo-git-b4177b89c08b3cd7c791f223b4828b4a81a62312.tar.gz
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: https://github.com/git/git/commit/7841c4801ce51f1f62d376d164372e8677c6bc94#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 <jvusich@amazon.com>
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/format/pktline/encoder.go3
-rw-r--r--plumbing/format/pktline/scanner.go2
-rw-r--r--plumbing/format/pktline/scanner_test.go16
3 files changed, 19 insertions, 2 deletions
diff --git a/plumbing/format/pktline/encoder.go b/plumbing/format/pktline/encoder.go
index eae85cc..6d40979 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 4af254f..99aab46 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 048ea38..9660c2d 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)