From 244cd62edb603f9397a5c6b7d0ac182c84074097 Mon Sep 17 00:00:00 2001 From: Calle Wilund Date: Mon, 11 Jan 2016 13:02:52 +0000 Subject: [PATCH] commit log reader bugfix: Fix tried to read entries across chunk bounds read_entry did not verify that current chunk has enough data left for a minimal entry. Thus we could try to read an entry from the slack left in a chunk, and get lost in the file (pos > next, skip very much -> eof). And also give false errors about corruption. --- db/commitlog/commitlog.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/db/commitlog/commitlog.cc b/db/commitlog/commitlog.cc index 9da70efaf7..9e36431c00 100644 --- a/db/commitlog/commitlog.cc +++ b/db/commitlog/commitlog.cc @@ -1350,6 +1350,17 @@ db::commitlog::read_log_file(file f, commit_load_reader_func next, position_type } future<> read_entry() { static constexpr size_t entry_header_size = segment::entry_overhead_size - sizeof(uint32_t); + + /** + * #598 - Must check that data left in chunk is enough to even read an entry. + * If not, this is small slack space in the chunk end, and we should just go + * to the next. + */ + assert(pos <= next); + if ((pos + entry_header_size) >= next) { + return skip(next - pos); + } + return fin.read_exactly(entry_header_size).then([this](temporary_buffer buf) { replay_position rp(id, position_type(pos));