Skip to content

fix(storage): throw instead of crashing on torn WAL tail reads - #1522

Merged
adsharma merged 1 commit into
release_0_22from
fix/torn-wal-replay-crash-0.22
Nov 6, 2026
Merged

adsharma merged 1 commit into
release_0_22from
fix/torn-wal-replay-crash-0.22

Conversation

@adsharma

@adsharma adsharma commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Backport of #1520 to release_0_22 (identical buggy code on this branch).

A WAL truncated mid-record (ENOSPC, power loss, SIGKILL mid-commit) crashed recovery with SIGSEGV/SIGBUS in both strict and lenient modes: BufferedFileReader::read copied the full requested size after a page refill without checking the short final page, overrunning the heap buffer inside WALRecord::deserialize <- dryReplay.

This loops small reads across page boundaries and pre-validates large reads against the file size, so torn tails surface as catchable replay errors: strict mode throws, lenient mode drops the torn transaction.

Adds WalTest.TornWALTailInsideLargeStringRecord covering a mid-string truncation of a multi-page WAL in both modes.

BufferedFileReader::read copied the full requested size after a page
refill without checking that the final page held that many bytes, so a
WAL truncated mid-record (ENOSPC, power loss, SIGKILL mid-commit)
overran the heap buffer and crashed recovery with SIGSEGV/SIGBUS in
both strict and lenient modes. Loop small reads across page boundaries
and pre-validate large reads against the file size, so torn tails
surface as catchable replay errors: strict mode throws and lenient mode
drops the torn transaction.

Add WalTest.TornWALTailInsideLargeStringRecord covering a mid-string
truncation of a multi-page WAL in both modes.

Backport of 423dbf7 to release_0_22 (without the checkpoint_test.cpp
build fix, which is not needed on this branch).
@adsharma
adsharma force-pushed the fix/torn-wal-replay-crash-0.22 branch from 199b071 to b9a04da Compare November 6, 2026 16:32
@adsharma
adsharma merged commit ec35ca5 into release_0_22 Nov 6, 2026
6 checks passed
@adsharma
adsharma deleted the fix/torn-wal-replay-crash-0.22 branch November 6, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant