From 76ae7f1641d61c954b592800da5432e28243d6a3 Mon Sep 17 00:00:00 2001 From: Michael Tuexen Date: Fri, 23 Feb 2024 12:27:18 +0100 Subject: [PATCH] Fix checksum check for received packets Only the following packets should be accepted: * Packets with a correct CRC32c checksum. * Packets with an incorrect zero checksum, if its acceptance is allowed. In particular, packets with an incorrect non-zero CRC32c must be discarded. --- packet.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packet.go b/packet.go index 316ca7d0..3bff1227 100644 --- a/packet.go +++ b/packet.go @@ -126,8 +126,8 @@ func (p *packet) unmarshal(doChecksum bool, raw []byte) error { offset += chunkHeaderSize + c.valueLength() + chunkValuePadding } - if doChecksum { - theirChecksum := binary.LittleEndian.Uint32(raw[8:]) + theirChecksum := binary.LittleEndian.Uint32(raw[8:]) + if theirChecksum != 0 || doChecksum { ourChecksum := generatePacketChecksum(raw) if theirChecksum != ourChecksum { return fmt.Errorf("%w: %d ours: %d", ErrChecksumMismatch, theirChecksum, ourChecksum)