Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(845)

Side by Side Diff: net/base/fuzzed_data_provider.h

Issue 1917503002: URLRequest fuzzer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fuzz
Patch Set: Response to comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 slices to
21 // provide more granular access to. |data| must outlive the
22 // FuzzedDataProvider.
23 FuzzedDataProvider(const uint8_t* data, size_t size);
24 ~FuzzedDataProvider();
25
26 // Tries to copy the first |bytes| remaining bytes from the input data to
27 // |dest|. If fewer than that many bytes of data remain, writes all the
28 // data that's left. Returns number of bytes written, which may be 0.
29 size_t ConsumeBytes(char* dest, size_t bytes);
30
31 // Returns a value with the specified number of bits of data. Returns 0 if
32 // there's no input data left. Pulls data from the end of the array. Despit
33 // its name, always consumes bits in multiples of 8, just throws away anything
34 // left over, to try and be more friendly to the mutations the fuzzer applies.
35 // |num_bits| must be less than 32.
36 uint32_t ConsumeBits(size_t num_bits);
37
38 // Same as ConsumeBits(1), but returns a bool.
39 bool ConsumeBool();
40
41 // Creates a value in the specified range, consuming only as much data is
42 // needed. Value may not uniformly distributed in that range.
43 uint32_t ConsumeValueInRange(uint32_t min, uint32_t max);
44
45 private:
46 base::StringPiece remaining_data_;
47
48 DISALLOW_COPY_AND_ASSIGN(FuzzedDataProvider);
49 };
50
51 } // namespace net
52
53 #endif // NET_BASE_FUZZED_DATA_PROVIDER_H
OLDNEW
« no previous file with comments | « net/BUILD.gn ('k') | net/base/fuzzed_data_provider.cc » ('j') | net/base/fuzzed_data_provider.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698