Fix: Header crc calculation

Signed-off-by: Thomas Klaehn <tkl@blackfinn.de>
This commit is contained in:
2026-02-13 10:15:45 +01:00
parent 2945d90d24
commit 8fbcb8562f

View File

@@ -54,12 +54,14 @@ func ParseHeader(data []byte) (*Header, error) {
if h.Size == HeaderWithCRCSize {
h.CRC = binary.LittleEndian.Uint16(data[12:14])
// Validate header CRC
// Validate header CRC (skip if CRC is 0x0000, which means "no validation")
if h.CRC != 0x0000 {
calculatedCRC := CalculateCRC(data[0:12])
if calculatedCRC != h.CRC {
return nil, fmt.Errorf("header CRC mismatch: got 0x%04X, expected 0x%04X", h.CRC, calculatedCRC)
}
}
}
return h, nil
}