From 2227d801a5fab7c3018f54d5f0f82ac23267df11 Mon Sep 17 00:00:00 2001 From: tangcong Date: Wed, 20 May 2020 12:35:25 +0800 Subject: [PATCH] wal: fix crc mismatch crash bug --- wal/wal.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wal/wal.go b/wal/wal.go index 5d0be5585a69..0f6fe64cfd4c 100644 --- a/wal/wal.go +++ b/wal/wal.go @@ -567,6 +567,14 @@ func ValidSnapshotEntries(lg *zap.Logger, walDir string) ([]walpb.Snapshot, erro snaps = append(snaps, loadedSnap) case stateType: state = mustUnmarshalState(rec.Data) + case crcType: + crc := decoder.crc.Sum32() + // current crc of decoder must match the crc of the record. + // do no need to match 0 crc, since the decoder is a new one at this case. + if crc != 0 && rec.Validate(crc) != nil { + return nil,ErrCRCMismatch + } + decoder.updateCRC(rec.Crc) } } // We do not have to read out all the WAL entries