Skip to content

Commit

Permalink
Fix checksum check for received packets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tuexen committed Feb 23, 2024
1 parent 5359da5 commit b42ee14
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b42ee14

Please sign in to comment.