Skip to content

Commit

Permalink
sstables: compressed_file_data_source_impl: get: throw malformed_ssta…
Browse files Browse the repository at this point in the history
…ble_exception on premature eof

Currently, the reader might dereference a null pointer
if the input stream reaches eof prematurely,
and read_exactly returns an empty temporary_buffer.

Detect this condition before dereferencing the buffer
and sstables::malformed_sstable_exception.

Fixes scylladb#13599

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
  • Loading branch information
bhalevy committed Apr 20, 2023
1 parent 6ca1b14 commit cbf4c9c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sstables/compress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ class compressed_file_data_source_impl : public data_source_impl {
throw std::runtime_error("compressed reader out of sync");
}
return _input_stream->read_exactly(addr.chunk_len).then([this, addr](temporary_buffer<char> buf) {
if (!buf.size()) {
throw sstables::malformed_sstable_exception(format("compressed reader hit premature end-of-file at file offset {}", addr.chunk_len, _underlying_pos));
}
return _permit.request_memory(_compression_metadata->uncompressed_chunk_length()).then(
[this, addr, buf = std::move(buf)] (reader_permit::resource_units res_units) mutable {
// The last 4 bytes of the chunk are the adler32/crc32 checksum
Expand Down

0 comments on commit cbf4c9c

Please sign in to comment.