From 541f0f2a41b0c47f41e63bd53fe8078e005629e2 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 29 Oct 2019 10:10:19 -0600 Subject: [PATCH] avoid buffer overflow on BE/LE conversions --- libp2p/protobuf/minprotobuf.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libp2p/protobuf/minprotobuf.nim b/libp2p/protobuf/minprotobuf.nim index 8fb37c5b3..4aae7761c 100644 --- a/libp2p/protobuf/minprotobuf.nim +++ b/libp2p/protobuf/minprotobuf.nim @@ -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)