avoid buffer overflow on BE/LE conversions

This commit is contained in:
Dmitriy Ryajov 2019-10-29 10:10:19 -06:00
parent cc0d45c482
commit 541f0f2a41
1 changed files with 2 additions and 2 deletions

View File

@ -199,11 +199,11 @@ proc finish*(pb: var ProtoBuffer) =
pb.buffer[0] = byte(size shr 24) pb.buffer[0] = byte(size shr 24)
pb.buffer[1] = byte(size shr 16) pb.buffer[1] = byte(size shr 16)
pb.buffer[2] = byte(size shr 8) pb.buffer[2] = byte(size shr 8)
pb.buffer[3] = byte(size) pb.buffer[3] = byte(size and 0xFF)
pb.offset = 4 pb.offset = 4
elif WithUint32LeLength in pb.options: elif WithUint32LeLength in pb.options:
let size = uint(len(pb.buffer) - 4) 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[1] = byte(size shr 8)
pb.buffer[2] = byte(size shr 16) pb.buffer[2] = byte(size shr 16)
pb.buffer[3] = byte(size shr 24) pb.buffer[3] = byte(size shr 24)