mirror of https://github.com/vacp2p/nim-libp2p.git
avoid buffer overflow on BE/LE conversions
This commit is contained in:
parent
cc0d45c482
commit
541f0f2a41
|
@ -199,11 +199,11 @@ proc finish*(pb: var ProtoBuffer) =
|
|||
pb.buffer[0] = byte(size shr 24)
|
||||
pb.buffer[1] = byte(size shr 16)
|
||||
pb.buffer[2] = byte(size shr 8)
|
||||
pb.buffer[3] = byte(size)
|
||||
pb.buffer[3] = byte(size and 0xFF)
|
||||
pb.offset = 4
|
||||
elif WithUint32LeLength in pb.options:
|
||||
let size = uint(len(pb.buffer) - 4)
|
||||
pb.buffer[0] = byte(size)
|
||||
pb.buffer[0] = byte(size and 0xFF)
|
||||
pb.buffer[1] = byte(size shr 8)
|
||||
pb.buffer[2] = byte(size shr 16)
|
||||
pb.buffer[3] = byte(size shr 24)
|
||||
|
|
Loading…
Reference in New Issue