From 400218ba01f2f0c6d0213d1f923c9aa407bd0cca Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 29 Oct 2019 11:02:28 -0600 Subject: [PATCH] fixing remaining overflows in BE/LE --- libp2p/protobuf/minprotobuf.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libp2p/protobuf/minprotobuf.nim b/libp2p/protobuf/minprotobuf.nim index 4aae7761c..888f8b6fd 100644 --- a/libp2p/protobuf/minprotobuf.nim +++ b/libp2p/protobuf/minprotobuf.nim @@ -196,17 +196,17 @@ proc finish*(pb: var ProtoBuffer) = pb.offset = pos elif WithUint32BeLength in pb.options: let size = uint(len(pb.buffer) - 4) - pb.buffer[0] = byte(size shr 24) - pb.buffer[1] = byte(size shr 16) - pb.buffer[2] = byte(size shr 8) + pb.buffer[0] = byte((size shr 24) and 0xFF) + pb.buffer[1] = byte((size shr 16) and 0xFF) + pb.buffer[2] = byte((size shr 8) and 0xFF) 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 and 0xFF) - pb.buffer[1] = byte(size shr 8) - pb.buffer[2] = byte(size shr 16) - pb.buffer[3] = byte(size shr 24) + pb.buffer[1] = byte((size shr 8) and 0xFF) + pb.buffer[2] = byte((size shr 16) and 0xFF) + pb.buffer[3] = byte((size shr 24) and 0xFF) pb.offset = 4 else: pb.offset = 0