Skip to content

Commit

Permalink
Commitlog replayer: Range-check skip call
Browse files Browse the repository at this point in the history
Fixes scylladb#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.
  • Loading branch information
Calle Wilund committed Sep 4, 2023
1 parent 9a3d572 commit c248e93
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions db/commitlog/commitlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2593,12 +2593,12 @@ 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);
return fin.skip(n);
}
void stop() {
eof = true;
Expand Down

0 comments on commit c248e93

Please sign in to comment.