Adapt to latest snappy; Avoid decompression bombs

This commit is contained in:
Zahary Karadjov 2020-08-19 14:14:59 +03:00
parent 5eff071c8e
commit 73c1bb817c
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 2 additions and 2 deletions

View File

@ -258,7 +258,7 @@ proc invokeThunk*(peer: Peer, msgId: int, msgData: var Rlp): Future[void] =
template compressMsg(peer: Peer, data: seq[byte]): seq[byte] =
when useSnappy:
if peer.snappyEnabled:
snappy.compress(data)
snappy.encode(data)
else: data
else:
data
@ -422,7 +422,7 @@ proc recvMsg*(peer: Peer): Future[tuple[msgId: int, msgData: Rlp]] {.async.} =
when useSnappy:
if peer.snappyEnabled:
decryptedBytes = snappy.uncompress(decryptedBytes)
decryptedBytes = snappy.decode(decryptedBytes, maxMsgSize)
if decryptedBytes.len == 0:
await peer.disconnectAndRaise(BreachOfProtocol,
"Snappy uncompress encountered malformed data")