| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_BASE_FUZZED_DATA_PROVIDER_H |
| 6 #define NET_BASE_FUZZED_DATA_PROVIDER_H |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/strings/string_piece.h" |
| 12 |
| 13 namespace net { |
| 14 |
| 15 // Utiliy class to break up fuzzer input for multiple consumers. Whenever run |
| 16 // on the same input, provides the same output, as long as its methods are |
| 17 // called in the same order, with the same arguments. |
| 18 class FuzzedDataProvider { |
| 19 public: |
| 20 FuzzedDataProvider(const uint8_t* data, size_t size); |
| 21 ~FuzzedDataProvider(); |
| 22 |
| 23 // Tries to copy the first |bytes| remaining bytes from the input data to |
| 24 // |dest|. If fewer than that many bytes of data remain, writes all the |
| 25 // data that's left. Returns number of bytes written, which may be 0. |
| 26 size_t ConsumeBytes(char* dest, size_t bytes); |
| 27 |
| 28 // Returns a value with the specified number of bits of data. Returns 0 if |
| 29 // there's no input data left. Pulls data from the end of the array. It's |
| 30 // recommended that bits be pulled in multiple of 8 (Through one or more |
| 31 // calls), since the fuzzer generates data by manipulations at the byte level. |
| 32 uint32_t ConsumeBits(size_t num_bits); |
| 33 |
| 34 private: |
| 35 base::StringPiece remaining_data_; |
| 36 |
| 37 uint8_t unused_bits_; |
| 38 uint8_t num_unused_bits_; |
| 39 |
| 40 DISALLOW_COPY_AND_ASSIGN(FuzzedDataProvider); |
| 41 }; |
| 42 |
| 43 } // namespace net |
| 44 |
| 45 #endif // NET_BASE_FUZZED_DATA_PROVIDER_H |
| OLD | NEW |