mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-13 06:04:42 +02:00
Merge bitcoin/bitcoin#34887: fuzz: target CDBWrapper
b63ef20d54test: add fuzz harness for CDBWrapper (Andrew Toth)32169c3855dbwrapper: accept optional testing leveldb::Env in DBParams (Andrew Toth)8d390c93fcdbwrapper: make max_file_size a configurable DBParams field (Andrew Toth) Pull request description: Inspired by https://github.com/bitcoin/bitcoin/pull/34866#issuecomment-4090291488. We currently don't have a dedicated harness targeting `CDBWrapper`. OSS-Fuzz has a [rudimentary harness](https://github.com/google/oss-fuzz/blob/master/projects/leveldb/fuzz_db.cc) for levelDB [which fails](https://issues.oss-fuzz.com/issues/447252244), so doesn't appear maintained. This PR adds a harness targeting `CDBWrapper` against an in-memory oracle to verify correctness. A `DeterministicEnv` wraps levelDB's `memenv` to eliminate non-determinism by capturing background compaction and running it at fuzzer-chosen points. The fuzzer also controls the cache_bytes and max_file_size sizes so that small values trigger memtable flushes and compaction. ACKs for top commit: l0rinc: code review ACKb63ef20d54marcofleon: ACKb63ef20d54dergoegge: utACKb63ef20d54sedited: ACKb63ef20d54Tree-SHA512: da1f738ec90c49830a05b8990bdaa474299b573e966e60f4febef1292d9682f2e50f0016831f26bf4677e5afdaa142dc8766d871c6bce90d35f1695d480ac8c1
This commit is contained in:
@@ -150,7 +150,6 @@ static leveldb::Options GetOptions(size_t nCacheSize)
|
||||
// on corruption in later versions.
|
||||
options.paranoid_checks = true;
|
||||
}
|
||||
options.max_file_size = std::max(options.max_file_size, DBWRAPPER_MAX_FILE_SIZE);
|
||||
SetMaxOpenFiles(&options);
|
||||
return options;
|
||||
}
|
||||
@@ -229,16 +228,23 @@ CDBWrapper::CDBWrapper(const DBParams& params)
|
||||
DBContext().syncoptions.sync = true;
|
||||
DBContext().options = GetOptions(params.cache_bytes);
|
||||
DBContext().options.create_if_missing = true;
|
||||
if (params.memory_only) {
|
||||
DBContext().options.max_file_size = params.max_file_size;
|
||||
assert(!(params.testing_env && params.memory_only));
|
||||
if (params.testing_env) {
|
||||
DBContext().options.env = params.testing_env;
|
||||
} else if (params.memory_only) {
|
||||
DBContext().penv = leveldb::NewMemEnv(leveldb::Env::Default());
|
||||
DBContext().options.env = DBContext().penv;
|
||||
} else {
|
||||
}
|
||||
if (!params.memory_only) {
|
||||
if (params.wipe_data) {
|
||||
LogInfo("Wiping LevelDB in %s", fs::PathToString(params.path));
|
||||
leveldb::Status result = leveldb::DestroyDB(fs::PathToString(params.path), DBContext().options);
|
||||
HandleError(result);
|
||||
}
|
||||
TryCreateDirectories(params.path);
|
||||
if (!params.testing_env) {
|
||||
TryCreateDirectories(params.path);
|
||||
}
|
||||
LogInfo("Opening LevelDB in %s", fs::PathToString(params.path));
|
||||
}
|
||||
// PathToString() return value is safe to pass to leveldb open function,
|
||||
|
||||
Reference in New Issue
Block a user