mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-09 22:06:21 +00:00
document snappy decompression assumptions
This commit is contained in:
parent
a605c7244e
commit
3c98f18d47
@ -42,15 +42,22 @@ proc uncompressFramedStream*(conn: Connection,
|
|||||||
|
|
||||||
let
|
let
|
||||||
crc = uint32.fromBytesLE frameData.toOpenArray(0, 3)
|
crc = uint32.fromBytesLE frameData.toOpenArray(0, 3)
|
||||||
todo = expectedSize - output.len
|
remaining = expectedSize - output.len
|
||||||
|
chunkLen = min(remaining, uncompressedData.len)
|
||||||
|
|
||||||
|
# Grab up to MAX_UNCOMPRESSED_DATA_LEN bytes, but no more than remains
|
||||||
|
# according to the expected size. If it turns out that the uncompressed
|
||||||
|
# data is longer than that, snappyUncompress will fail and we will not
|
||||||
|
# decompress the chunk at all, instead reporting failure.
|
||||||
|
let
|
||||||
uncompressedLen = snappyUncompress(
|
uncompressedLen = snappyUncompress(
|
||||||
frameData.toOpenArray(4, dataLen - 1),
|
frameData.toOpenArray(4, dataLen - 1),
|
||||||
uncompressedData.toOpenArray(0, min(todo, uncompressedData.len) - 1))
|
uncompressedData.toOpenArray(0, chunkLen - 1))
|
||||||
|
|
||||||
if uncompressedLen <= 0:
|
if uncompressedLen <= 0:
|
||||||
return err "Failed to decompress snappy frame"
|
return err "Failed to decompress snappy frame"
|
||||||
doAssert output.len + uncompressedLen <= expectedSize,
|
doAssert output.len + uncompressedLen <= expectedSize,
|
||||||
"enforced by `min` above"
|
"enforced by `remains` limit above"
|
||||||
|
|
||||||
if not checkCrc(uncompressedData.toOpenArray(0, uncompressedLen-1), crc):
|
if not checkCrc(uncompressedData.toOpenArray(0, uncompressedLen-1), crc):
|
||||||
return err "Snappy content CRC checksum failed"
|
return err "Snappy content CRC checksum failed"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user