Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2023-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <test/fuzz/FuzzedDataProvider.h>6#include <test/fuzz/fuzz.h>7#include <test/fuzz/util.h>8#include <test/util/setup_common.h>9#include <util/fs.h>10#include <util/time.h>11#include <util/translation.h>12#include <wallet/db.h>13#include <wallet/dump.h>14#include <wallet/migrate.h>16#include <fstream>17#include <iostream>19using wallet::DatabaseOptions;20using wallet::DatabaseStatus;22namespace {23TestingSetup* g_setup;24} // namespace26void initialize_wallet_bdb_parser()27{28static auto testing_setup = MakeNoLogFileContext<TestingSetup>();29g_setup = testing_setup.get();30}32FUZZ_TARGET(wallet_bdb_parser, .init = initialize_wallet_bdb_parser)33{34const auto wallet_path = g_setup->m_args.GetDataDirNet() / "fuzzed_wallet.dat";36{37AutoFile outfile{fsbridge::fopen(wallet_path, "wb")};38outfile << std::span{buffer};39assert(outfile.fclose() == 0);40}42const DatabaseOptions options{};43DatabaseStatus status;44bilingual_str error;46fs::path bdb_ro_dumpfile{g_setup->m_args.GetDataDirNet() / "fuzzed_dumpfile_bdb_ro.dump"};47if (fs::exists(bdb_ro_dumpfile)) { // Writing into an existing dump file will throw an exception48remove(bdb_ro_dumpfile);49}50g_setup->m_args.ForceSetArg("-dumpfile", fs::PathToString(bdb_ro_dumpfile));52auto db{MakeBerkeleyRODatabase(wallet_path, options, status, error)};53if (db) {54assert(DumpWallet(g_setup->m_args, *db, error));55} else {56if (error.original.starts_with("AutoFile::ignore: end of file") ||57error.original.starts_with("AutoFile::read: end of file") ||58error.original.starts_with("AutoFile::seek: ") ||59error.original == "Not a BDB file" ||60error.original == "Unexpected page type, should be 9 (BTree Metadata)" ||61error.original == "Unexpected database flags, should only be 0x20 (subdatabases)" ||62error.original == "Unexpected outer database root page type" ||63error.original == "Unexpected number of entries in outer database root page" ||64error.original == "Subdatabase page number has unexpected length" ||65error.original == "Unknown record type in records page" ||66error.original == "Unknown record type in internal page" ||67error.original == "Unexpected page size" ||68error.original == "Unexpected page type" ||69error.original == "Page number mismatch" ||70error.original == "Bad btree level" ||71error.original == "Bad page size" ||72error.original == "Meta page number mismatch" ||73error.original == "Data record position not in page" ||74error.original == "Internal record position not in page" ||75error.original == "LSNs are not reset, this database is not completely flushed. Please reopen then close the database with a version that has BDB support" ||76error.original == "Records page has odd number of records" ||77error.original == "Bad overflow record page type" ||78error.original == "BTree page has an unexpected level" ||79error.original == "BTree Leaf page is not at level 1" ||80error.original == "Subdatabase last page is greater than database last page" ||81error.original == "Page number is greater than database last page" ||82error.original == "Last page number could not fit in file" ||83error.original == "Subdatabase has an unexpected name" ||84error.original == "Unsupported BDB data file version number" ||85error.original == "BDB builtin encryption is not supported") {86} else {87throw std::runtime_error(error.original);88}89}90}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.