Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
buffered_file.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <span.h>
6#include <streams.h>
7#include <test/fuzz/fuzz.h>
9#include <test/fuzz/util.h>
10#include <util/obfuscation.h>
11
12#include <array>
13#include <cstddef>
14#include <cstdint>
15#include <iostream>
16#include <optional>
17#include <vector>
18
20{
21 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
23 std::optional<BufferedFile> opt_buffered_file;
27 Obfuscation{std::span{key_bytes}.first<Obfuscation::KEY_SIZE>()},
28 };
29 try {
33 } catch (const std::ios_base::failure&) {
34 }
35 if (opt_buffered_file && !fuzzed_file.IsNull()) {
36 bool setpos_fail = false;
38 {
41 [&] {
42 std::array<std::byte, 4096> arr{};
43 try {
44 opt_buffered_file->read({arr.data(), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096)});
45 } catch (const std::ios_base::failure&) {
46 }
47 },
48 [&] {
50 },
51 [&] {
53 setpos_fail = true;
54 }
55 },
56 [&] {
57 if (setpos_fail) {
58 // Calling FindByte(...) after a failed SetPos(...) call may result in an infinite loop.
59 return;
60 }
61 try {
63 } catch (const std::ios_base::failure&) {
64 }
65 },
66 [&] {
68 });
69 }
70 opt_buffered_file->GetPos();
71 }
72}
void ReadFromStream(AddrMan &addr, DataStream &ssPeers)
Only used by tests.
Definition addrdb.cpp:191
Non-refcounted RAII wrapper for FILE*.
Definition streams.h:373
T ConsumeIntegralInRange(T min, T max)
static constexpr size_t KEY_SIZE
Definition obfuscation.h:23
#define FUZZ_TARGET(...)
Definition fuzz.h:35
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition fuzz.h:22
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
Definition util.h:35
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:73
FuzzedDataProvider & fuzzed_data_provider
Definition fees.cpp:38