| 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 // Utility 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 // |data| is an array of length |size| that the FuzzedDataProvider wraps to |
| 21 // provide more granular access. |data| must outlive the FuzzedDataProvider. |
| 22 FuzzedDataProvider(const uint8_t* data, size_t size); |
| 23 ~FuzzedDataProvider(); |
| 24 |
| 25 // Tries to copy the first |bytes| remaining bytes from the input data to |
| 26 // |dest|. If fewer than that many bytes of data remain, writes all the |
| 27 // data that's left. Returns number of bytes written, which may be 0. |
| 28 size_t ConsumeBytes(char* dest, size_t bytes); |
| 29 |
| 30 // Returns a value from |min| to |max| inclusive, extracting a value from the |
| 31 // input data in some unspecified manner. Value may not be uniformly |
| 32 // distributed in the given range. If there's no input data left, always |
| 33 // returns |min|. |min| must be less than or equal to |max|. |
| 34 uint32_t ConsumeValueInRange(uint32_t min, uint32_t max); |
| 35 |
| 36 // Returns a value with the specified number of bits of data. Returns 0 if |
| 37 // there's no input data left. |num_bits| must non-zero, and at most 32. |
| 38 // Basically the same as ConsumeValueInRange((1 << num_bits) - 1); |
| 39 uint32_t ConsumeBits(size_t num_bits); |
| 40 |
| 41 // Same as ConsumeBits(1), but returns a bool. |
| 42 bool ConsumeBool(); |
| 43 |
| 44 private: |
| 45 base::StringPiece remaining_data_; |
| 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(FuzzedDataProvider); |
| 48 }; |
| 49 |
| 50 } // namespace net |
| 51 |
| 52 #endif // NET_BASE_FUZZED_DATA_PROVIDER_H |
| OLD | NEW |