Coverage Report

Created: 2025-03-18 19:28

/root/bitcoin/src/test/fuzz/autofile.cpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2020-2022 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/FuzzedDataProvider.h>
8
#include <test/fuzz/fuzz.h>
9
#include <test/fuzz/util.h>
10
11
#include <array>
12
#include <cstddef>
13
#include <cstdio>
14
#include <iostream>
15
#include <vector>
16
17
FUZZ_TARGET(autofile)
18
0
{
19
0
    FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
20
0
    FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
21
0
    AutoFile auto_file{
22
0
        fuzzed_file_provider.open(),
23
0
        ConsumeRandomLengthByteVector<std::byte>(fuzzed_data_provider),
24
0
    };
25
0
    LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 100)
26
0
    {
27
0
        CallOneOf(
28
0
            fuzzed_data_provider,
29
0
            [&] {
30
0
                std::array<std::byte, 4096> arr{};
31
0
                try {
32
0
                    auto_file.read({arr.data(), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096)});
33
0
                } catch (const std::ios_base::failure&) {
34
0
                }
35
0
            },
36
0
            [&] {
37
0
                const std::array<std::byte, 4096> arr{};
38
0
                try {
39
0
                    auto_file.write({arr.data(), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096)});
40
0
                } catch (const std::ios_base::failure&) {
41
0
                }
42
0
            },
43
0
            [&] {
44
0
                try {
45
0
                    auto_file.ignore(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
46
0
                } catch (const std::ios_base::failure&) {
47
0
                }
48
0
            },
49
0
            [&] {
50
0
                auto_file.fclose();
51
0
            },
52
0
            [&] {
53
0
                ReadFromStream(fuzzed_data_provider, auto_file);
54
0
            },
55
0
            [&] {
56
0
                WriteToStream(fuzzed_data_provider, auto_file);
57
0
            });
58
0
    }
59
0
    (void)auto_file.IsNull();
60
0
    if (fuzzed_data_provider.ConsumeBool()) {
  Branch (60:9): [True: 0, False: 0]
61
0
        FILE* f = auto_file.release();
62
0
        if (f != nullptr) {
  Branch (62:13): [True: 0, False: 0]
63
0
            fclose(f);
64
0
        }
65
0
    }
66
0
}