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) 2020-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 <span.h>6#include <streams.h>7#include <test/fuzz/fuzz.h>8#include <test/fuzz/FuzzedDataProvider.h>9#include <test/fuzz/util.h>10#include <util/obfuscation.h>12#include <array>13#include <cstddef>14#include <cstdio>15#include <iostream>16#include <vector>18FUZZ_TARGET(autofile)19{20FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};21FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};22const auto key_bytes{ConsumeFixedLengthByteVector<std::byte>(fuzzed_data_provider, Obfuscation::KEY_SIZE)};23AutoFile auto_file{24fuzzed_file_provider.open(),25Obfuscation{std::span{key_bytes}.first<Obfuscation::KEY_SIZE>()},26};27LIMITED_WHILE (fuzzed_data_provider.ConsumeBool(), 100) {28CallOneOf(29fuzzed_data_provider,30[&] {31std::array<std::byte, 4096> arr{};32try {33auto_file.read({arr.data(), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096)});34} catch (const std::ios_base::failure&) {35}36},37[&] {38const std::array<std::byte, 4096> arr{};39try {40auto_file.write({arr.data(), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096)});41} catch (const std::ios_base::failure&) {42}43},44[&] {45try {46auto_file.ignore(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));47} catch (const std::ios_base::failure&) {48}49},50[&] {51(void)auto_file.fclose();52},53[&] {54ReadFromStream(fuzzed_data_provider, auto_file);55},56[&] {57WriteToStream(fuzzed_data_provider, auto_file);58});59}60(void)auto_file.IsNull();61if (fuzzed_data_provider.ConsumeBool()) {62FILE* f = auto_file.release();63if (f != nullptr) {64fclose(f);65}66} else {67(void)auto_file.fclose();68}69}
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.