// Legacy (unqlite-format) database files are parsed by the daemon on its // first start (import). A corrupt or truncated file must be rejected, never // crash or allocate beyond the file's own size; an accepted file re-saves to // an equivalent map. #include "../src/store/legacy_kv.hpp" #include #include #include #include #include using namespace strawberry; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { static const std::string dir = (std::filesystem::temp_directory_path() / ("sb-fuzz-kv-" + std::to_string(::getpid()))).string(); std::filesystem::create_directories(dir); const std::string path = dir + "/db"; if (FILE* f = std::fopen(path.c_str(), "wb")) { std::fwrite(data, 1, size, f); std::fclose(f); } auto loaded = legacy_kv::database::load(path); if (!loaded) return 0; { auto db = legacy_kv::database::open(path + ".copy", legacy_kv::open_mode::create); if (!db) __builtin_trap(); for (const auto& [k, v] : *loaded) { if (!db->store(k, v)) __builtin_trap(); } } auto again = legacy_kv::database::load(path + ".copy"); std::filesystem::remove(path + ".copy"); if (!again || *again != *loaded) __builtin_trap(); return 0; }