Merge pull request #2 from Clever/dont-log-not-enough-data
Check if buffer read is complete before decoding
This commit is contained in:
commit
dc1af95307
@ -2,6 +2,7 @@ package worker
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"encoding/binary"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@ -77,7 +78,8 @@ func (a *agent) work() {
|
|||||||
if len(leftdata) > 0 { // some data left for processing
|
if len(leftdata) > 0 { // some data left for processing
|
||||||
data = append(leftdata, data...)
|
data = append(leftdata, data...)
|
||||||
}
|
}
|
||||||
if len(data) < minPacketLength { // not enough data
|
length := len(data) - minPacketLength
|
||||||
|
if length < 0 || length < int(binary.BigEndian.Uint32(data[8:12])) {
|
||||||
leftdata = data
|
leftdata = data
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,8 @@ func (inpack *inPack) UpdateStatus(numerator, denominator int) {
|
|||||||
|
|
||||||
// Decode job from byte slice
|
// Decode job from byte slice
|
||||||
func decodeInPack(data []byte) (inpack *inPack, l int, err error) {
|
func decodeInPack(data []byte) (inpack *inPack, l int, err error) {
|
||||||
|
// The next three checks should be completely unnecessary, as they are checked in
|
||||||
|
// agent.work.
|
||||||
if len(data) < minPacketLength { // valid package should not less 12 bytes
|
if len(data) < minPacketLength { // valid package should not less 12 bytes
|
||||||
err = fmt.Errorf("Invalid data: %v", data)
|
err = fmt.Errorf("Invalid data: %v", data)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user