Limit metadata size
Malicious or malfunctioning peer can try send a huge metadata size what causes huge memory usage and to overflow them.
This commit is contained in:
parent
2251664dbd
commit
14979c96ce
@ -22,6 +22,7 @@ import os
|
|||||||
|
|
||||||
from . import bencode
|
from . import bencode
|
||||||
|
|
||||||
|
MAX_METADATA_SIZE = 5*1024*1024
|
||||||
|
|
||||||
InfoHash = bytes
|
InfoHash = bytes
|
||||||
PeerAddress = typing.Tuple[str, int]
|
PeerAddress = typing.Tuple[str, int]
|
||||||
@ -209,7 +210,8 @@ class DisposablePeer:
|
|||||||
# Just to make sure that the remote peer supports ut_metadata extension:
|
# Just to make sure that the remote peer supports ut_metadata extension:
|
||||||
ut_metadata = msg_dict[b"m"][b"ut_metadata"]
|
ut_metadata = msg_dict[b"m"][b"ut_metadata"]
|
||||||
metadata_size = msg_dict[b"metadata_size"]
|
metadata_size = msg_dict[b"metadata_size"]
|
||||||
assert metadata_size > 0
|
assert metadata_size > 0, "Invalid (empty) metada size"
|
||||||
|
assert metadata_size < MAX_METADATA_SIZE, "Malicious or malfunctioning peer tried send a huge metadata size"
|
||||||
except (AssertionError, KeyError):
|
except (AssertionError, KeyError):
|
||||||
self.when_error()
|
self.when_error()
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user