diff --git a/db/db_test.cc b/db/db_test.cc index 0204f4d9f..69e91923c 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -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) { diff --git a/table/block_based/block_based_table_factory.cc b/table/block_based/block_based_table_factory.cc index 00b13033f..96812e233 100644 --- a/table/block_based/block_based_table_factory.cc +++ b/table/block_based/block_based_table_factory.cc @@ -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) {