Skip to content

Commit

Permalink
Commitlog replayer: Range-check skip call
Browse files Browse the repository at this point in the history
Fixes #15269

If segment being replayed is corrupted/truncated we can attempt skipping
completely bogues byte amounts, which can cause assert (i.e. crash) in
file_data_source_impl. This is not a crash-level error, so ensure we
range check the distance in the reader.

v2: Add to corrupt_size if trying to skip more than available. The amount added is "wrong", but at least will
    ensure we log the fact that things are broken

Closes #15270

(cherry picked from commit 6ffb482)
  • Loading branch information
Calle Wilund authored and denesb committed Jan 5, 2024
1 parent f126ccb commit e3153dd
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions db/commitlog/commitlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2628,12 +2628,20 @@ db::commitlog::read_log_file(sstring filename, sstring pfx, commit_load_reader_f
return eof || next == pos;
}
future<> skip(size_t bytes) {
pos += bytes;
if (pos > file_size) {
auto n = std::min(file_size - pos, bytes);
pos += n;
if (pos == file_size) {
eof = true;
pos = file_size;
}
return fin.skip(bytes);
if (n < bytes) {
// if we are trying to skip past end, we have at least
// the bytes skipped or the source from where we read
// this corrupt. So add at least four bytes. This is
// inexact, but adding the full "bytes" is equally wrong
// since it could be complete garbled junk.
corrupt_size += std::max(n, sizeof(uint32_t));
}
return fin.skip(n);
}
void stop() {
eof = true;
Expand Down

0 comments on commit e3153dd

Please sign in to comment.