| 15 | #include <vector> |
| 16 | |
| 17 | FUZZ_TARGET(autofile) |
| 18 | { |
| 19 | FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; |
| 20 | FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider); |
| 21 | CAutoFile auto_file = fuzzed_auto_file_provider.open(); |
| 22 | LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) { |
| 23 | CallOneOf( |
| 24 | fuzzed_data_provider, |
| 25 | [&] { |
| 26 | std::array<std::byte, 4096> arr{}; |
| 27 | try { |
| 28 | auto_file.read({arr.data(), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096)}); |
| 29 | } catch (const std::ios_base::failure&) { |
| 30 | } |
| 31 | }, |
| 32 | [&] { |
| 33 | const std::array<std::byte, 4096> arr{}; |
| 34 | try { |
| 35 | auto_file.write({arr.data(), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096)}); |
| 36 | } catch (const std::ios_base::failure&) { |
| 37 | } |
| 38 | }, |
| 39 | [&] { |
| 40 | try { |
| 41 | auto_file.ignore(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096)); |
| 42 | } catch (const std::ios_base::failure&) { |
| 43 | } |
| 44 | }, |
| 45 | [&] { |
| 46 | auto_file.fclose(); |
| 47 | }, |
| 48 | [&] { |
| 49 | ReadFromStream(fuzzed_data_provider, auto_file); |
| 50 | }, |
| 51 | [&] { |
| 52 | WriteToStream(fuzzed_data_provider, auto_file); |
| 53 | }); |
| 54 | } |
| 55 | (void)auto_file.Get(); |
| 56 | (void)auto_file.GetType(); |
| 57 | (void)auto_file.GetVersion(); |
| 58 | (void)auto_file.IsNull(); |
| 59 | if (fuzzed_data_provider.ConsumeBool()) { |
| 60 | FILE* f = auto_file.release(); |
| 61 | if (f != nullptr) { |
| 62 | fclose(f); |
| 63 | } |
| 64 | } |
| 65 | } |
nothing calls this directly
no test coverage detected