sanitize and limit block_size under 4GB (#5492)
Summary: `Block::restart_index_`, `Block::restarts_`, and `Block::current_` are defined as uint32_t but `BlockBasedTableOptions::block_size` is defined as a size_t so user might see corruption as in https://github.com/facebook/rocksdb/issues/5486. This PR adds a check in `BlockBasedTableFactory::SanitizeOptions` to disallow such configurations. yiwu-arbug Pull Request resolved: https://github.com/facebook/rocksdb/pull/5492 Differential Revision: D15914047 Pulled By: miasantreble fbshipit-source-id: c943f153d967e15aee7f2795730ab8259e2be201
This commit is contained in:
parent
68614a9608
commit
24f73436fb
@ -6156,6 +6156,17 @@ TEST_F(DBTest, ThreadLocalPtrDeadlock) {
|
||||
fprintf(stderr, "Done. Flushed %d times, destroyed %d threads\n",
|
||||
flushes_done.load(), threads_destroyed.load());
|
||||
}
|
||||
|
||||
TEST_F(DBTest, LargeBlockSizeTest) {
|
||||
Options options = CurrentOptions();
|
||||
CreateAndReopenWithCF({"pikachu"}, options);
|
||||
ASSERT_OK(Put(0, "foo", "bar"));
|
||||
BlockBasedTableOptions table_options;
|
||||
table_options.block_size = 8LL*1024*1024*1024LL;
|
||||
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
|
||||
ASSERT_NOK(TryReopenWithColumnFamilies({"default", "pikachu"}, options));
|
||||
}
|
||||
|
||||
} // namespace rocksdb
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
@ -257,6 +257,10 @@ Status BlockBasedTableFactory::SanitizeOptions(
|
||||
return Status::InvalidArgument(
|
||||
"Block alignment requested but block size is not a power of 2");
|
||||
}
|
||||
if (table_options_.block_size > port::kMaxUint32) {
|
||||
return Status::InvalidArgument(
|
||||
"block size exceeds maximum number (4GiB) allowed");
|
||||
}
|
||||
if (table_options_.data_block_index_type ==
|
||||
BlockBasedTableOptions::kDataBlockBinaryAndHash &&
|
||||
table_options_.data_block_hash_table_util_ratio <= 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user