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

Side by Side Diff: media/base/bit_reader_fuzzertest.cc

Issue 1754523004: media: Add fuzzer test for bit_reader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: inline arithmetic Created 4 years, 9 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
« no previous file with comments | « media/base/bit_reader_core.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <stddef.h>
mmoroz 2016/03/09 10:20:48 Could you please include <stdint.h> too? May be it
jrummell 2016/03/09 19:08:21 Done.
6
7 #include "base/hash.h"
8 #include "base/numerics/safe_conversions.h"
9 #include "media/base/bit_reader.h"
10 #include "media/base/test_random.h"
11
12 // Entry point for LibFuzzer.
13 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
14 media::BitReader reader(data, base::checked_cast<int>(size));
15
16 // Need a simple random number generator to generate the number of bits to
17 // read/skip in a reproducible way (given the same |data|). Using Hash() to
18 // ensure the seed varies significantly over minor changes in |data|.
19 media::TestRandom rnd(base::Hash(reinterpret_cast<const char*>(data), size));
20
21 // Read and skip through the data in |reader|.
22 while (reader.bits_available() > 0) {
23 if (rnd.Rand() & 1) {
24 // Read up to 64 bits. This may fail if there is not enough bits
25 // remaining, but it doesn't matter (testing for failures is also good).
26 uint64_t value;
27 if (!reader.ReadBits(rnd.Rand() % 64 + 1, &value))
28 break;
29 } else {
30 // Skip up to 128 bits. As above, this may fail.
31 if (!reader.SkipBits(rnd.Rand() % 128 + 1))
32 break;
33 }
34 }
35 return 0;
36 }
OLDNEW
« no previous file with comments | « media/base/bit_reader_core.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698