Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wal): fix recover with insufficient buffer #568

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion server/wal/codec/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (v *V2) RecoverIndex(buf []byte, startFileOffset uint32, baseEntryOffset in

index = BorrowEmptyIndexBuf()

for newFileOffset < maxSize {
for newFileOffset+v.HeaderSize <= maxSize {
var payloadSize uint32
var payloadCrc uint32
var err error
Expand Down
11 changes: 11 additions & 0 deletions server/wal/codec/v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,14 @@ func TestV2_ReadWithValidation(t *testing.T) {
assert.NoError(t, err)
assert.EqualValues(t, wPayloadCrc, rPayloadCrc)
}

func TestV2_RecoveryWithNotEnoughBuf(t *testing.T) {
buf := make([]byte, 16)
payloadSize := uint32(len(buf)) - v2.HeaderSize - 1
payload := bytes.Repeat([]byte("A"), int(payloadSize))
_, wPayloadCrc := v2.WriteRecord(buf, 0, 0, payload)
_, rLastCrc, _, entryOffset, err := v2.RecoverIndex(buf, 0, 0, nil)
assert.NoError(t, err)
assert.EqualValues(t, wPayloadCrc, rLastCrc)
assert.EqualValues(t, entryOffset, 0)
}
Loading