Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit59b792b

Browse files
committed
plumbing: fix sideband demux on flush
Canonical Git implementation terminates the sideband stream with aflush. If the demux scanner is not terminated, it can hang theconnection. Returns io.EOF when encountering a flush pkt.https://github.com/git/git/blob/master/upload-pack.c#L460
1 parent1ddd78a commit59b792b

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

‎plumbing/protocol/packp/sideband/demux.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (d *Demuxer) nextPackData() ([]byte, error) {
114114

115115
size:=len(content)
116116
ifsize==0 {
117-
returnnil,nil
117+
returnnil,io.EOF
118118
}elseifsize>d.max {
119119
returnnil,ErrMaxPackedExceeded
120120
}

‎plumbing/protocol/packp/sideband/demux_test.go‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,34 @@ func (s *SidebandSuite) TestDecodeWithProgress(c *C) {
105105
c.Assert(progress,DeepEquals, []byte{'F','O','O','\n'})
106106
}
107107

108-
func (s*SidebandSuite)TestDecodeWithUnknownChannel(c*C) {
108+
func (s*SidebandSuite)TestDecodeFlushEOF(c*C) {
109+
expected:= []byte("abcdefghijklmnopqrstuvwxyz")
110+
111+
input:=bytes.NewBuffer(nil)
112+
e:=pktline.NewEncoder(input)
113+
e.Encode(PackData.WithPayload(expected[0:8]))
114+
e.Encode(ProgressMessage.WithPayload([]byte{'F','O','O','\n'}))
115+
e.Encode(PackData.WithPayload(expected[8:16]))
116+
e.Encode(PackData.WithPayload(expected[16:26]))
117+
e.Flush()
118+
e.Encode(PackData.WithPayload([]byte("bar\n")))
119+
120+
output:=bytes.NewBuffer(nil)
121+
content:=bytes.NewBuffer(nil)
122+
d:=NewDemuxer(Sideband64k,input)
123+
d.Progress=output
124+
125+
n,err:=content.ReadFrom(d)
126+
c.Assert(err,IsNil)
127+
c.Assert(n,Equals,int64(26))
128+
c.Assert(content.Bytes(),DeepEquals,expected)
109129

130+
progress,err:=io.ReadAll(output)
131+
c.Assert(err,IsNil)
132+
c.Assert(progress,DeepEquals, []byte{'F','O','O','\n'})
133+
}
134+
135+
func (s*SidebandSuite)TestDecodeWithUnknownChannel(c*C) {
110136
buf:=bytes.NewBuffer(nil)
111137
e:=pktline.NewEncoder(buf)
112138
e.Encode([]byte{'4','F','O','O','\n'})
@@ -150,5 +176,4 @@ func (s *SidebandSuite) TestDecodeErrMaxPacked(c *C) {
150176
n,err:=io.ReadFull(d,content)
151177
c.Assert(err,Equals,ErrMaxPackedExceeded)
152178
c.Assert(n,Equals,0)
153-
154179
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp