LCOV - code coverage report
Current view: top level - src/test/fuzz - util.h (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 144 144
Test Date: 2024-09-01 05:20:30 Functions: 99.4 % 161 160
Branches: 72.4 % 1024 741

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2009-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                 :             : #ifndef BITCOIN_TEST_FUZZ_UTIL_H
       6                 :             : #define BITCOIN_TEST_FUZZ_UTIL_H
       7                 :             : 
       8                 :             : #include <addresstype.h>
       9                 :             : #include <arith_uint256.h>
      10                 :             : #include <coins.h>
      11                 :             : #include <compat/compat.h>
      12                 :             : #include <consensus/amount.h>
      13                 :             : #include <consensus/consensus.h>
      14                 :             : #include <key.h>
      15                 :             : #include <merkleblock.h>
      16                 :             : #include <primitives/transaction.h>
      17                 :             : #include <script/script.h>
      18                 :             : #include <serialize.h>
      19                 :             : #include <streams.h>
      20                 :             : #include <test/fuzz/FuzzedDataProvider.h>
      21                 :             : #include <test/fuzz/fuzz.h>
      22                 :             : #include <uint256.h>
      23                 :             : 
      24                 :             : #include <algorithm>
      25                 :             : #include <array>
      26                 :             : #include <cstdint>
      27                 :             : #include <cstdio>
      28                 :             : #include <optional>
      29                 :             : #include <string>
      30                 :             : #include <vector>
      31                 :             : 
      32                 :             : class PeerManager;
      33                 :             : 
      34                 :             : template <typename... Callables>
      35                 :    44075211 : size_t CallOneOf(FuzzedDataProvider& fuzzed_data_provider, Callables... callables)
      36                 :             : {
      37                 :    44075211 :     constexpr size_t call_size{sizeof...(callables)};
      38                 :             :     static_assert(call_size >= 1);
      39                 :    44075211 :     const size_t call_index{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, call_size - 1)};
      40                 :             : 
      41                 :    44075211 :     size_t i{0};
      42   [ +  +  +  +  :    44075211 :     ((i++ == call_index ? callables() : void()), ...);
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
             +  +  +  +  
           + ][ +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
           + ][ +  +  +  
          +  +  +  +  +  
          +  +  +  +  #  
          #  #  #  #  #  
          #  #  #  #  #  
           # ][ +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
             +  +  +  + ]
           [ +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
           + ][ +  +  +  
           +  +  + ][ +  
          +  +  +  +  +  
          +  +  +  +  #  
             #  #  #  #  
           # ][ +  +  +  
             +  +  +  +  
           + ][ +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
           +  + ][ +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
             +  +  +  +  
           + ][ +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  #  # ][ +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  #  # ][ +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
           +  + ][ +  +  
          +  +  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  #  # ][ +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
           +  + ][ +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
           +  + ][ +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
             +  +  +  + ]
           [ +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
      43                 :    44069963 :     return call_size;
      44                 :    44069963 : }
      45                 :             : 
      46                 :             : template <typename Collection>
      47                 :     6022943 : auto& PickValue(FuzzedDataProvider& fuzzed_data_provider, Collection& col)
      48                 :             : {
      49                 :     6022943 :     auto sz{col.size()};
      50         [ +  - ]:     6022943 :     assert(sz >= 1);
           [ +  -  +  - ]
           [ +  -  +  -  
                   +  - ]
      51                 :     6022943 :     auto it = col.begin();
      52                 :     6022943 :     std::advance(it, fuzzed_data_provider.ConsumeIntegralInRange<decltype(sz)>(0, sz - 1));
      53                 :    12045886 :     return *it;
      54                 :     6022943 : }
      55                 :             : 
      56                 :             : template<typename B = uint8_t>
      57                 :     3517996 : [[nodiscard]] inline std::vector<B> ConsumeRandomLengthByteVector(FuzzedDataProvider& fuzzed_data_provider, const std::optional<size_t>& max_length = std::nullopt) noexcept
      58                 :             : {
      59                 :             :     static_assert(sizeof(B) == 1);
      60         [ +  + ]:     7035992 :     const std::string s = max_length ?
      61         [ +  - ]:      465419 :                               fuzzed_data_provider.ConsumeRandomLengthString(*max_length) :
      62         [ +  - ]:     3052577 :                               fuzzed_data_provider.ConsumeRandomLengthString();
      63         [ +  - ]:     3517996 :     std::vector<B> ret(s.size());
      64         [ +  - ]:     3517996 :     std::copy(s.begin(), s.end(), reinterpret_cast<char*>(ret.data()));
      65                 :     3517996 :     return ret;
      66         [ +  - ]:     3517996 : }
      67                 :             : 
      68                 :        6781 : [[nodiscard]] inline std::vector<bool> ConsumeRandomLengthBitVector(FuzzedDataProvider& fuzzed_data_provider, const std::optional<size_t>& max_length = std::nullopt) noexcept
      69                 :             : {
      70         [ +  - ]:        6781 :     return BytesToBits(ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length));
      71                 :             : }
      72                 :             : 
      73                 :        8598 : [[nodiscard]] inline DataStream ConsumeDataStream(FuzzedDataProvider& fuzzed_data_provider, const std::optional<size_t>& max_length = std::nullopt) noexcept
      74                 :             : {
      75   [ +  -  +  - ]:        8598 :     return DataStream{ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length)};
      76                 :             : }
      77                 :             : 
      78                 :      447083 : [[nodiscard]] inline std::vector<std::string> ConsumeRandomLengthStringVector(FuzzedDataProvider& fuzzed_data_provider, const size_t max_vector_size = 16, const size_t max_string_length = 16) noexcept
      79                 :             : {
      80         [ +  - ]:      447083 :     const size_t n_elements = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, max_vector_size);
      81                 :      447083 :     std::vector<std::string> r;
      82         [ +  + ]:     2915899 :     for (size_t i = 0; i < n_elements; ++i) {
      83   [ +  -  +  - ]:     2468816 :         r.push_back(fuzzed_data_provider.ConsumeRandomLengthString(max_string_length));
      84                 :     2468816 :     }
      85                 :      447083 :     return r;
      86         [ +  - ]:      447083 : }
      87                 :             : 
      88                 :             : template <typename T>
      89                 :        3200 : [[nodiscard]] inline std::vector<T> ConsumeRandomLengthIntegralVector(FuzzedDataProvider& fuzzed_data_provider, const size_t max_vector_size = 16) noexcept
      90                 :             : {
      91         [ +  - ]:        3200 :     const size_t n_elements = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, max_vector_size);
      92                 :        3200 :     std::vector<T> r;
      93         [ +  + ]:       16242 :     for (size_t i = 0; i < n_elements; ++i) {
      94   [ +  -  +  - ]:       13042 :         r.push_back(fuzzed_data_provider.ConsumeIntegral<T>());
      95                 :       13042 :     }
      96                 :        3200 :     return r;
      97         [ +  - ]:        3200 : }
      98                 :             : 
      99                 :             : template <typename P>
     100                 :             : [[nodiscard]] P ConsumeDeserializationParams(FuzzedDataProvider& fuzzed_data_provider) noexcept;
     101                 :             : 
     102                 :             : template <typename T, typename P>
     103                 :      485556 : [[nodiscard]] std::optional<T> ConsumeDeserializable(FuzzedDataProvider& fuzzed_data_provider, const P& params, const std::optional<size_t>& max_length = std::nullopt) noexcept
     104                 :             : {
     105                 :      485556 :     const std::vector<uint8_t> buffer{ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length)};
     106   [ +  -  +  - ]:      485556 :     DataStream ds{buffer};
           [ #  #  #  #  
             #  #  #  # ]
           [ +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     107         [ +  - ]:      485556 :     T obj;
           [ #  #  #  # ]
           [ +  -  +  -  
             +  -  +  - ]
     108                 :             :     try {
     109   [ +  -  +  + ]:      485556 :         ds >> params(obj);
           [ #  #  #  #  
             #  #  #  # ]
           [ +  -  +  +  
          +  -  +  +  +  
          -  +  +  +  -  
                   +  + ]
     110         [ +  - ]:      485556 :     } catch (const std::ios_base::failure&) {
           [ #  #  #  # ]
           [ +  -  +  -  
             +  -  +  - ]
     111                 :        8643 :         return std::nullopt;
     112         [ +  - ]:        8643 :     }
           [ #  #  #  # ]
           [ +  -  +  -  
             +  -  +  - ]
     113                 :      476913 :     return obj;
     114                 :      494199 : }
     115                 :             : 
     116                 :             : template <typename T>
     117                 :     1184706 : [[nodiscard]] inline std::optional<T> ConsumeDeserializable(FuzzedDataProvider& fuzzed_data_provider, const std::optional<size_t>& max_length = std::nullopt) noexcept
     118                 :             : {
     119                 :     1184706 :     const std::vector<uint8_t> buffer = ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length);
     120   [ +  -  +  - ]:     1184706 :     DataStream ds{buffer};
           [ #  #  #  #  
          +  -  +  -  +  
           -  +  - ][ +  
          -  +  -  +  -  
          +  -  #  #  #  
                      # ]
     121         [ +  - ]:     1184706 :     T obj;
           [ #  #  +  - ]
     122                 :             :     try {
     123 [ +  + ][ #  #  :     1184706 :         ds >> obj;
             +  +  +  + ]
           [ +  +  +  +  
                   #  # ]
     124 [ +  - ][ #  #  :     1184706 :     } catch (const std::ios_base::failure&) {
             +  -  +  - ]
           [ +  -  +  -  
                   #  # ]
     125                 :      337556 :         return std::nullopt;
     126 [ +  - ][ #  #  :      337556 :     }
             +  -  +  - ]
           [ +  -  +  -  
                   #  # ]
     127         [ +  - ]:      847150 :     return obj;
     128                 :     1522262 : }
     129                 :             : 
     130                 :             : template <typename WeakEnumType, size_t size>
     131                 :     4726799 : [[nodiscard]] WeakEnumType ConsumeWeakEnum(FuzzedDataProvider& fuzzed_data_provider, const WeakEnumType (&all_types)[size]) noexcept
     132                 :             : {
     133   [ +  -  +  + ]:     9453598 :     return fuzzed_data_provider.ConsumeBool() ?
     134         [ +  - ]:     4632490 :                fuzzed_data_provider.PickValueInArray<WeakEnumType>(all_types) :
     135         [ +  - ]:       94309 :                WeakEnumType(fuzzed_data_provider.ConsumeIntegral<typename std::underlying_type<WeakEnumType>::type>());
     136                 :             : }
     137                 :             : 
     138                 :      879503 : [[nodiscard]] inline opcodetype ConsumeOpcodeType(FuzzedDataProvider& fuzzed_data_provider) noexcept
     139                 :             : {
     140         [ +  - ]:      879503 :     return static_cast<opcodetype>(fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(0, MAX_OPCODE));
     141                 :             : }
     142                 :             : 
     143                 :             : [[nodiscard]] CAmount ConsumeMoney(FuzzedDataProvider& fuzzed_data_provider, const std::optional<CAmount>& max = std::nullopt) noexcept;
     144                 :             : 
     145                 :             : [[nodiscard]] int64_t ConsumeTime(FuzzedDataProvider& fuzzed_data_provider, const std::optional<int64_t>& min = std::nullopt, const std::optional<int64_t>& max = std::nullopt) noexcept;
     146                 :             : 
     147                 :             : [[nodiscard]] CMutableTransaction ConsumeTransaction(FuzzedDataProvider& fuzzed_data_provider, const std::optional<std::vector<Txid>>& prevout_txids, const int max_num_in = 10, const int max_num_out = 10) noexcept;
     148                 :             : 
     149                 :             : [[nodiscard]] CScriptWitness ConsumeScriptWitness(FuzzedDataProvider& fuzzed_data_provider, const size_t max_stack_elem_size = 32) noexcept;
     150                 :             : 
     151                 :             : [[nodiscard]] CScript ConsumeScript(FuzzedDataProvider& fuzzed_data_provider, const bool maybe_p2wsh = false) noexcept;
     152                 :             : 
     153                 :             : [[nodiscard]] uint32_t ConsumeSequence(FuzzedDataProvider& fuzzed_data_provider) noexcept;
     154                 :             : 
     155                 :      597734 : [[nodiscard]] inline CScriptNum ConsumeScriptNum(FuzzedDataProvider& fuzzed_data_provider) noexcept
     156                 :             : {
     157   [ +  -  +  - ]:      597734 :     return CScriptNum{fuzzed_data_provider.ConsumeIntegral<int64_t>()};
                 [ +  - ]
     158                 :             : }
     159                 :             : 
     160                 :       10899 : [[nodiscard]] inline uint160 ConsumeUInt160(FuzzedDataProvider& fuzzed_data_provider) noexcept
     161                 :             : {
     162         [ +  - ]:       10899 :     const std::vector<uint8_t> v160 = fuzzed_data_provider.ConsumeBytes<uint8_t>(160 / 8);
     163         [ +  + ]:       10899 :     if (v160.size() != 160 / 8) {
     164         [ +  - ]:        1063 :         return {};
     165                 :             :     }
     166   [ +  -  +  - ]:        9836 :     return uint160{v160};
     167                 :       10899 : }
     168                 :             : 
     169                 :      204911 : [[nodiscard]] inline uint256 ConsumeUInt256(FuzzedDataProvider& fuzzed_data_provider) noexcept
     170                 :             : {
     171         [ +  - ]:      204911 :     const std::vector<uint8_t> v256 = fuzzed_data_provider.ConsumeBytes<uint8_t>(256 / 8);
     172         [ +  + ]:      204911 :     if (v256.size() != 256 / 8) {
     173         [ +  - ]:        2692 :         return {};
     174                 :             :     }
     175   [ +  -  +  - ]:      202219 :     return uint256{v256};
     176                 :      204911 : }
     177                 :             : 
     178                 :       90228 : [[nodiscard]] inline arith_uint256 ConsumeArithUInt256(FuzzedDataProvider& fuzzed_data_provider) noexcept
     179                 :             : {
     180         [ +  - ]:       90228 :     return UintToArith256(ConsumeUInt256(fuzzed_data_provider));
     181                 :             : }
     182                 :             : 
     183                 :             : [[nodiscard]] std::map<COutPoint, Coin> ConsumeCoins(FuzzedDataProvider& fuzzed_data_provider) noexcept;
     184                 :             : 
     185                 :             : [[nodiscard]] CTxDestination ConsumeTxDestination(FuzzedDataProvider& fuzzed_data_provider) noexcept;
     186                 :             : 
     187                 :             : [[nodiscard]] CKey ConsumePrivateKey(FuzzedDataProvider& fuzzed_data_provider, std::optional<bool> compressed = std::nullopt) noexcept;
     188                 :             : 
     189                 :             : template <typename T>
     190                 :        2310 : [[nodiscard]] bool MultiplicationOverflow(const T i, const T j) noexcept
     191                 :             : {
     192                 :             :     static_assert(std::is_integral<T>::value, "Integral required.");
     193                 :             :     if (std::numeric_limits<T>::is_signed) {
     194   [ +  +  +  +  :        1422 :         if (i > 0) {
          +  +  +  +  +  
              + ][ +  + ]
     195   [ +  +  +  +  :         285 :             if (j > 0) {
          +  +  +  +  +  
              + ][ +  + ]
     196                 :         163 :                 return i > (std::numeric_limits<T>::max() / j);
     197                 :             :             } else {
     198                 :         122 :                 return j < (std::numeric_limits<T>::min() / i);
     199                 :             :             }
     200                 :             :         } else {
     201   [ +  +  +  +  :        1137 :             if (j > 0) {
          +  +  +  +  +  
              + ][ +  + ]
     202                 :         208 :                 return i < (std::numeric_limits<T>::min() / j);
     203                 :             :             } else {
     204   [ +  +  +  +  :         929 :                 return i != 0 && (j < (std::numeric_limits<T>::max() / i));
          +  +  +  +  +  
              + ][ +  + ]
     205                 :             :             }
     206                 :             :         }
     207                 :             :     } else {
     208   [ +  +  +  +  :         888 :         return j != 0 && i > std::numeric_limits<T>::max() / j;
             +  +  +  + ]
     209                 :             :     }
     210                 :        1422 : }
     211                 :             : 
     212                 :             : [[nodiscard]] bool ContainsSpentInput(const CTransaction& tx, const CCoinsViewCache& inputs) noexcept;
     213                 :             : 
     214                 :             : /**
     215                 :             :  * Sets errno to a value selected from the given std::array `errnos`.
     216                 :             :  */
     217                 :             : template <typename T, size_t size>
     218                 :       10571 : void SetFuzzedErrNo(FuzzedDataProvider& fuzzed_data_provider, const std::array<T, size>& errnos)
     219                 :             : {
     220                 :       10571 :     errno = fuzzed_data_provider.PickValueInArray(errnos);
     221                 :       10571 : }
     222                 :             : 
     223                 :             : /*
     224                 :             :  * Sets a fuzzed errno in the range [0, 133 (EHWPOISON)]. Can be used from functions emulating
     225                 :             :  * standard library functions that set errno, or in other contexts where the value of errno
     226                 :             :  * might be relevant for the execution path that will be taken.
     227                 :             :  */
     228                 :      108466 : inline void SetFuzzedErrNo(FuzzedDataProvider& fuzzed_data_provider) noexcept
     229                 :             : {
     230         [ +  - ]:      108466 :     errno = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 133);
     231                 :      108466 : }
     232                 :             : 
     233                 :             : /**
     234                 :             :  * Returns a byte vector of specified size regardless of the number of remaining bytes available
     235                 :             :  * from the fuzzer. Pads with zero value bytes if needed to achieve the specified size.
     236                 :             :  */
     237                 :             : template<typename B = uint8_t>
     238                 :      116988 : [[nodiscard]] inline std::vector<B> ConsumeFixedLengthByteVector(FuzzedDataProvider& fuzzed_data_provider, const size_t length) noexcept
     239                 :             : {
     240                 :             :     static_assert(sizeof(B) == 1);
     241         [ +  - ]:      116988 :     auto random_bytes = fuzzed_data_provider.ConsumeBytes<B>(length);
     242         [ +  - ]:      116988 :     random_bytes.resize(length);
     243                 :      116988 :     return random_bytes;
     244         [ +  - ]:      116988 : }
     245                 :             : 
     246                 :             : class FuzzedFileProvider
     247                 :             : {
     248                 :             :     FuzzedDataProvider& m_fuzzed_data_provider;
     249                 :        5336 :     int64_t m_offset = 0;
     250                 :             : 
     251                 :             : public:
     252                 :        5336 :     FuzzedFileProvider(FuzzedDataProvider& fuzzed_data_provider) : m_fuzzed_data_provider{fuzzed_data_provider}
     253                 :             :     {
     254                 :        5336 :     }
     255                 :             : 
     256                 :             :     FILE* open();
     257                 :             : 
     258                 :             :     static ssize_t read(void* cookie, char* buf, size_t size);
     259                 :             : 
     260                 :             :     static ssize_t write(void* cookie, const char* buf, size_t size);
     261                 :             : 
     262                 :             :     static int seek(void* cookie, int64_t* offset, int whence);
     263                 :             : 
     264                 :             :     static int close(void* cookie);
     265                 :             : };
     266                 :             : 
     267                 :             : #define WRITE_TO_STREAM_CASE(type, consume) \
     268                 :             :     [&] {                                   \
     269                 :             :         type o = consume;                   \
     270                 :             :         stream << o;                        \
     271                 :             :     }
     272                 :             : template <typename Stream>
     273                 :        5145 : void WriteToStream(FuzzedDataProvider& fuzzed_data_provider, Stream& stream) noexcept
     274                 :             : {
     275   [ +  -  +  + ]:      120238 :     while (fuzzed_data_provider.ConsumeBool()) {
     276                 :             :         try {
     277         [ +  + ]:      117943 :             CallOneOf(
     278                 :      117943 :                 fuzzed_data_provider,
     279                 :      127172 :                 WRITE_TO_STREAM_CASE(bool, fuzzed_data_provider.ConsumeBool()),
     280                 :      125959 :                 WRITE_TO_STREAM_CASE(int8_t, fuzzed_data_provider.ConsumeIntegral<int8_t>()),
     281                 :      124220 :                 WRITE_TO_STREAM_CASE(uint8_t, fuzzed_data_provider.ConsumeIntegral<uint8_t>()),
     282                 :      120506 :                 WRITE_TO_STREAM_CASE(int16_t, fuzzed_data_provider.ConsumeIntegral<int16_t>()),
     283                 :      120247 :                 WRITE_TO_STREAM_CASE(uint16_t, fuzzed_data_provider.ConsumeIntegral<uint16_t>()),
     284                 :      130986 :                 WRITE_TO_STREAM_CASE(int32_t, fuzzed_data_provider.ConsumeIntegral<int32_t>()),
     285                 :      119215 :                 WRITE_TO_STREAM_CASE(uint32_t, fuzzed_data_provider.ConsumeIntegral<uint32_t>()),
     286                 :      119698 :                 WRITE_TO_STREAM_CASE(int64_t, fuzzed_data_provider.ConsumeIntegral<int64_t>()),
     287                 :      123492 :                 WRITE_TO_STREAM_CASE(uint64_t, fuzzed_data_provider.ConsumeIntegral<uint64_t>()),
     288         [ +  + ]:      183013 :                 WRITE_TO_STREAM_CASE(std::string, fuzzed_data_provider.ConsumeRandomLengthString(32)),
     289         [ +  + ]:      120808 :                 WRITE_TO_STREAM_CASE(std::vector<uint8_t>, ConsumeRandomLengthIntegralVector<uint8_t>(fuzzed_data_provider)));
     290         [ +  - ]:      117943 :         } catch (const std::ios_base::failure&) {
     291                 :             :             break;
     292         [ +  - ]:        2850 :         }
     293                 :             :     }
     294                 :        7995 : }
     295                 :             : 
     296                 :             : #define READ_FROM_STREAM_CASE(type) \
     297                 :             :     [&] {                           \
     298                 :             :         type o;                     \
     299                 :             :         stream >> o;                \
     300                 :             :     }
     301                 :             : template <typename Stream>
     302                 :       13072 : void ReadFromStream(FuzzedDataProvider& fuzzed_data_provider, Stream& stream) noexcept
     303                 :             : {
     304   [ +  -  +  + ]:      101481 :     while (fuzzed_data_provider.ConsumeBool()) {
     305                 :             :         try {
     306         [ +  + ]:       99005 :             CallOneOf(
     307                 :       99005 :                 fuzzed_data_provider,
     308                 :      102878 :                 READ_FROM_STREAM_CASE(bool),
     309                 :      101606 :                 READ_FROM_STREAM_CASE(int8_t),
     310                 :      103224 :                 READ_FROM_STREAM_CASE(uint8_t),
     311                 :      104670 :                 READ_FROM_STREAM_CASE(int16_t),
     312                 :      101802 :                 READ_FROM_STREAM_CASE(uint16_t),
     313                 :      107361 :                 READ_FROM_STREAM_CASE(int32_t),
     314                 :      106956 :                 READ_FROM_STREAM_CASE(uint32_t),
     315                 :      123534 :                 READ_FROM_STREAM_CASE(int64_t),
     316                 :      103030 :                 READ_FROM_STREAM_CASE(uint64_t),
     317         [ +  + ]:      118448 :                 READ_FROM_STREAM_CASE(std::string),
     318         [ +  + ]:      114551 :                 READ_FROM_STREAM_CASE(std::vector<uint8_t>));
     319         [ +  - ]:       99005 :         } catch (const std::ios_base::failure&) {
     320                 :             :             break;
     321         [ +  - ]:       10596 :         }
     322                 :             :     }
     323                 :       23668 : }
     324                 :             : 
     325                 :             : #endif // BITCOIN_TEST_FUZZ_UTIL_H
        

Generated by: LCOV version 2.0-1