@ -12,9 +12,33 @@
# include "rocksdb/file_system.h"
# include "rocksdb/file_system.h"
# include "rocksdb/sst_file_writer.h"
# include "rocksdb/sst_file_writer.h"
# include "src/libfuzzer/libfuzzer_macro.h"
# include "src/libfuzzer/libfuzzer_macro.h"
# include "table/table_builder.h"
# include "table/table_reader.h"
# include "table/table_reader.h"
# include "util.h"
# include "util.h"
using ROCKSDB_NAMESPACE : : BytewiseComparator ;
using ROCKSDB_NAMESPACE : : Comparator ;
using ROCKSDB_NAMESPACE : : EnvOptions ;
using ROCKSDB_NAMESPACE : : ExternalSstFileInfo ;
using ROCKSDB_NAMESPACE : : FileOptions ;
using ROCKSDB_NAMESPACE : : FileSystem ;
using ROCKSDB_NAMESPACE : : ImmutableCFOptions ;
using ROCKSDB_NAMESPACE : : ImmutableOptions ;
using ROCKSDB_NAMESPACE : : InternalIterator ;
using ROCKSDB_NAMESPACE : : IOOptions ;
using ROCKSDB_NAMESPACE : : kMaxSequenceNumber ;
using ROCKSDB_NAMESPACE : : Options ;
using ROCKSDB_NAMESPACE : : ParsedInternalKey ;
using ROCKSDB_NAMESPACE : : ParseInternalKey ;
using ROCKSDB_NAMESPACE : : RandomAccessFileReader ;
using ROCKSDB_NAMESPACE : : ReadOptions ;
using ROCKSDB_NAMESPACE : : SstFileWriter ;
using ROCKSDB_NAMESPACE : : Status ;
using ROCKSDB_NAMESPACE : : TableReader ;
using ROCKSDB_NAMESPACE : : TableReaderCaller ;
using ROCKSDB_NAMESPACE : : TableReaderOptions ;
using ROCKSDB_NAMESPACE : : ValueType ;
// Keys in SST file writer operations must be unique and in ascending order.
// Keys in SST file writer operations must be unique and in ascending order.
// For each DBOperation generated by the fuzzer, this function is called on
// For each DBOperation generated by the fuzzer, this function is called on
// it to deduplicate and sort the keys in the DBOperations.
// it to deduplicate and sort the keys in the DBOperations.
@ -60,15 +84,15 @@ TableReader* NewTableReader(const std::string& sst_file_path,
std : : unique_ptr < TableReader > table_reader ;
std : : unique_ptr < TableReader > table_reader ;
const auto & fs = options . env - > GetFileSystem ( ) ;
const auto & fs = options . env - > GetFileSystem ( ) ;
FileOptions fopts ( env_options ) ;
FileOptions fopts ( env_options ) ;
Status s = options . env - > GetFileSize ( sst_file_path , fopts . io_options ,
Status s = options . env - > GetFileSize ( sst_file_path , & file_size ) ;
& file_size , nullptr ) ;
if ( s . ok ( ) ) {
if ( s . ok ( ) ) {
s = RandomAccessFileReader : : Create ( fs , sst_file_path , fopts , & file_reader ,
s = RandomAccessFileReader : : Create ( fs , sst_file_path , fopts , & file_reader ,
nullptr ) ;
nullptr ) ;
}
}
if ( s . ok ( ) ) {
if ( s . ok ( ) ) {
TableReaderOptions t_opt ( cf_ioptions , /*prefix_extractor=*/ nullptr ,
ImmutableOptions iopts ( options , cf_ioptions ) ;
env_options , cf_ioptions . internal_comparator ) ;
TableReaderOptions t_opt ( iopts , /*prefix_extractor=*/ nullptr , env_options ,
cf_ioptions . internal_comparator ) ;
t_opt . largest_seqno = kMaxSequenceNumber ;
t_opt . largest_seqno = kMaxSequenceNumber ;
s = options . table_factory - > NewTableReader ( t_opt , std : : move ( file_reader ) ,
s = options . table_factory - > NewTableReader ( t_opt , std : : move ( file_reader ) ,
file_size , & table_reader ,
file_size , & table_reader ,
@ -153,7 +177,7 @@ DEFINE_PROTO_FUZZER(DBOperations& input) {
// Iterate and verify key-value pairs.
// Iterate and verify key-value pairs.
std : : unique_ptr < TableReader > table_reader (
std : : unique_ptr < TableReader > table_reader (
NewTableReader ( sstfile , options , env_options , cf_ioptions ) ) ;
: : NewTableReader ( sstfile , options , env_options , cf_ioptions ) ) ;
ReadOptions roptions ;
ReadOptions roptions ;
CHECK_OK ( table_reader - > VerifyChecksum ( roptions ,
CHECK_OK ( table_reader - > VerifyChecksum ( roptions ,
TableReaderCaller : : kUncategorized ) ) ;
TableReaderCaller : : kUncategorized ) ) ;