UDT: Fix another bug, this time in udtSocket.Read. This UDT library is a fucking piece of !@#$ code that deserves a special place in hell. It probably takes longer fixing this piece of !@#$ than writing a new library from scratch. booh!

This commit is contained in:
Kleissner
2021-11-04 17:05:53 +01:00
parent e141510b9c
commit e6846c232c

View File

@@ -201,39 +201,28 @@ func (s *udtSocket) Read(p []byte) (n int, err error) {
err = errors.New("Message truncated") // <- evil buggy
}
} else {
// for streaming sockets, block until we have at least something to return, then
// fill up the passed buffer as far as we can without blocking again
idx := 0
l := len(p)
n = 0
for idx < l {
if s.currPartialRead == nil {
// for streaming sockets, block until we have at least something to return, then fill up the passed buffer as far as we can without blocking again
for offset := 0; offset < len(p); {
if len(s.currPartialRead) == 0 {
// Grab the next data packet
currPartialRead, rerr := s.fetchReadPacket(n == 0 && connErr == nil)
s.currPartialRead = currPartialRead
if rerr != nil {
err = rerr
return
if s.currPartialRead, err = s.fetchReadPacket(n == 0 && connErr == nil); err != nil {
return n, err
}
if s.currPartialRead == nil {
if len(s.currPartialRead) == 0 {
if n != 0 {
return
}
if connErr != nil {
err = connErr
return
return n, connErr
}
}
}
thisN := copy(p[idx:], s.currPartialRead)
n = n + thisN
idx = idx + thisN
if n >= len(s.currPartialRead) {
// we've exhausted the current data packet, reset to nil
s.currPartialRead = nil
} else {
s.currPartialRead = s.currPartialRead[n:]
}
thisN := copy(p[offset:], s.currPartialRead)
n += thisN
offset += thisN
s.currPartialRead = s.currPartialRead[thisN:]
}
}
return