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

Unified Diff: net/base/fuzzed_data_provider.h

Issue 1917503002: URLRequest fuzzer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fuzz
Patch Set: Add missing include Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/BUILD.gn ('k') | net/base/fuzzed_data_provider.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/fuzzed_data_provider.h
diff --git a/net/base/fuzzed_data_provider.h b/net/base/fuzzed_data_provider.h
new file mode 100644
index 0000000000000000000000000000000000000000..d892c30fbecd737553f73dd7ef92fa89da14d063
--- /dev/null
+++ b/net/base/fuzzed_data_provider.h
@@ -0,0 +1,54 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_BASE_FUZZED_DATA_PROVIDER_H
+#define NET_BASE_FUZZED_DATA_PROVIDER_H
+
+#include <stdint.h>
+
+#include "base/macros.h"
+#include "base/strings/string_piece.h"
+
+namespace net {
+
+// Utility class to break up fuzzer input for multiple consumers. Whenever run
+// on the same input, provides the same output, as long as its methods are
+// called in the same order, with the same arguments.
+class FuzzedDataProvider {
+ public:
+ // |data| is an array of length |size| that the FuzzedDataProvider wraps to
+ // provide more granular access. |data| must outlive the FuzzedDataProvider.
+ FuzzedDataProvider(const uint8_t* data, size_t size);
+ ~FuzzedDataProvider();
+
+ // Returns a StringPiece containing |length| bytes of the input data. If fewer
+ // than that many bytes remain, returns a shorter StringPiece containing all
+ // of the data that's left. The data pointed at by the returned StringPiece
+ // must not be used after the FuzzedDataProvider is destroyed.
+ base::StringPiece ConsumeBytes(size_t bytes);
eroman 2016/04/28 18:32:33 FYI: In some follow-up changes I am reviewing, ano
Charlie Harrison 2016/04/28 18:37:42 Yeah I was actually planning on adding this method
mmenke 2016/04/28 18:38:29 I was thinking I'd probably need something like th
eroman 2016/04/28 18:45:48 sgtm
+
+ // Returns a value from |min| to |max| inclusive, extracting a value from the
+ // input data in some unspecified manner. Value may not be uniformly
+ // distributed in the given range. If there's no input data left, always
+ // returns |min|. |min| must be less than or equal to |max|.
+ uint32_t ConsumeValueInRange(uint32_t min, uint32_t max);
+
+ // Returns a value with the specified number of bits of data. Returns 0 if
+ // there's no input data left. |num_bits| must non-zero, and at most 32.
+ // Basically the same as ConsumeValueInRange((1 << num_bits) - 1);
+ uint32_t ConsumeBits(size_t num_bits);
+
+ // Same as ConsumeBits(1), but returns a bool. Returns false when there's no
+ // data remaining.
+ bool ConsumeBool();
+
+ private:
+ base::StringPiece remaining_data_;
+
+ DISALLOW_COPY_AND_ASSIGN(FuzzedDataProvider);
+};
+
+} // namespace net
+
+#endif // NET_BASE_FUZZED_DATA_PROVIDER_H
« no previous file with comments | « net/BUILD.gn ('k') | net/base/fuzzed_data_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698