[magneticod] fix OOM caused by large BT msg size

This commit is contained in:
Bora M. Alper 2019-05-19 17:23:36 +01:00
parent 3c6fc334ad
commit 738e5c1e0f
No known key found for this signature in database
GPG Key ID: 8F1A9504E1BD114D

View File

@ -184,6 +184,14 @@ func (l *Leech) readMessage() ([]byte, error) {
rLength := uint(binary.BigEndian.Uint32(rLengthB))
// Some malicious/faulty peers say that they are sending a very long
// message, and hence causing us to run out of memory.
// This is a crude check that does not let it happen (i.e. boundary can probably be
// tightened a lot more.)
if rLength > MAX_METADATA_SIZE {
return nil, errors.New("message is longer than max allowed metadata size")
}
rMessage, err := l.readExactly(rLength)
if err != nil {
return nil, errors.Wrap(err, "readExactly rMessage")