Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,7 @@ func (mb *msgBlock) rebuildStateLocked() (*LostStreamData, []uint64, error) {

// To detect gaps from compaction, and to ensure the sequence keeps moving up.
var last uint64
var hb [highwayhash.Size64]byte

for index, lbuf := uint32(0), uint32(len(buf)); index < lbuf; {
if index+msgHdrSize > lbuf {
Expand Down Expand Up @@ -1548,7 +1549,7 @@ func (mb *msgBlock) rebuildStateLocked() (*LostStreamData, []uint64, error) {
} else {
hh.Write(data[slen : dlen-recordHashSize])
}
checksum := hh.Sum(nil)
checksum := hh.Sum(hb[:0])
if !bytes.Equal(checksum, data[len(data)-recordHashSize:]) {
truncate(index)
return gatherLost(lbuf - index), tombstones, errBadMsg{mb.mfn, "invalid checksum"}
Expand Down Expand Up @@ -1742,7 +1743,8 @@ func (fs *fileStore) recoverFullState() (rerr error) {
buf = buf[:len(buf)-highwayhash.Size64]
fs.hh.Reset()
fs.hh.Write(buf)
if !bytes.Equal(h, fs.hh.Sum(nil)) {
var hb [highwayhash.Size64]byte
if !bytes.Equal(h, fs.hh.Sum(hb[:0])) {
os.Remove(fn)
fs.warn("Stream state checksum did not match")
return errCorruptState
Expand Down Expand Up @@ -5470,7 +5472,8 @@ func (mb *msgBlock) eraseMsg(seq uint64, ri, rl int, isLastBlock bool) error {
mb.hh.Reset()
mb.hh.Write(hdr[4:20])
mb.hh.Write(data)
checksum := mb.hh.Sum(nil)
var hb [highwayhash.Size64]byte
checksum := mb.hh.Sum(hb[:0])
// Write to msg record.
b.Write(checksum)

Expand Down Expand Up @@ -7687,7 +7690,8 @@ func (mb *msgBlock) msgFromBufEx(buf []byte, sm *StoreMsg, hh hash.Hash64, doCop
} else {
hh.Write(data[slen : dlen-recordHashSize])
}
if !bytes.Equal(hh.Sum(nil), data[len(data)-8:]) {
var hb [highwayhash.Size64]byte
if !bytes.Equal(hh.Sum(hb[:0]), data[len(data)-8:]) {
return nil, errBadMsg{mb.mfn, "invalid checksum"}
}
}
Expand Down