diff --git a/table/plain_table_index.cc b/table/plain_table_index.cc index b3fc288ff..efba9b71d 100644 --- a/table/plain_table_index.cc +++ b/table/plain_table_index.cc @@ -16,15 +16,20 @@ inline uint32_t GetBucketIdFromHash(uint32_t hash, uint32_t num_buckets) { } } -void PlainTableIndex::InitFromRawData(Slice data) { - assert(GetVarint32(&data, &index_size_)); +Status PlainTableIndex::InitFromRawData(Slice data) { + if (!GetVarint32(&data, &index_size_)) { + return Status::Corruption("Couldn't read the index size!"); + } assert(index_size_ > 0); - assert(GetVarint32(&data, &num_prefixes_)); + if (!GetVarint32(&data, &num_prefixes_)) { + return Status::Corruption("Couldn't read the index size!"); + } sub_index_size_ = data.size() - index_size_ * kOffsetLen; char* index_data_begin = const_cast(data.data()); index_ = reinterpret_cast(index_data_begin); sub_index_ = reinterpret_cast(index_ + index_size_); + return Status::OK(); } PlainTableIndex::IndexSearchResult PlainTableIndex::GetOffset( diff --git a/table/plain_table_index.h b/table/plain_table_index.h index 347bb0f05..f63bbd0d5 100644 --- a/table/plain_table_index.h +++ b/table/plain_table_index.h @@ -72,7 +72,7 @@ class PlainTableIndex { IndexSearchResult GetOffset(uint32_t prefix_hash, uint32_t* bucket_value) const; - void InitFromRawData(Slice data); + Status InitFromRawData(Slice data); const char* GetSubIndexBasePtrAndUpperBound(uint32_t offset, uint32_t* upper_bound) const { diff --git a/table/plain_table_reader.cc b/table/plain_table_reader.cc index e20446f1e..8728eb1d3 100644 --- a/table/plain_table_reader.cc +++ b/table/plain_table_reader.cc @@ -236,8 +236,8 @@ Status PlainTableReader::PopulateIndexRecordList( } prefix_hashes->push_back(GetSliceHash(key_prefix_slice)); - index_.InitFromRawData(index_builder->Finish()); - return Status::OK(); + auto s = index_.InitFromRawData(index_builder->Finish()); + return s; } void PlainTableReader::AllocateAndFillBloom(int bloom_bits_per_key, @@ -357,7 +357,10 @@ Status PlainTableReader::PopulateIndex(TableProperties* props, return s; } } else { - index_.InitFromRawData(*index_block); + Status s = index_.InitFromRawData(*index_block); + if (!s.ok()) { + return s; + } } if (!index_in_file) {