-
Notifications
You must be signed in to change notification settings - Fork 868
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Bug Description
When pktline.ReadLine()is called, the function returns its buffer to the pool while keeping the reference of the buffer. This can lead to memory corruption, as the buffer may be reused and overwritten by other goroutines at any time.
go-git/plumbing/format/pktline/pktline.go
Lines 164 to 174 in 48f817f
| func ReadLine(r io.Reader) (l int, p []byte, err error) { | |
| buf := GetBuffer() | |
| defer PutBuffer(buf) | |
| l, err = Read(r, (*buf)[:]) | |
| if l < LenSize { | |
| return l, nil, err | |
| } | |
| return l, (*buf)[LenSize:l], err | |
| } |
go-git Version
Steps to Reproduce
func TestConcurrentReadLine(t *testing.T) {
var wg sync.WaitGroup
for n := range 30 {
wg.Add(1)
go func() {
defer wg.Done()
data := strconv.Itoa(n)
var buf bytes.Buffer
_, err := pktline.Write(&buf, []byte(data))
require.NoError(t, err)
_, p, err := pktline.ReadLine(&buf)
require.NoError(t, err)
assert.Equal(t, data, string(p))
}()
}
wg.Wait()
}Additional Information
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working