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

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: add include 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>
6 #include <stdint.h>
7
8 #include "base/hash.h"
9 #include "base/numerics/safe_conversions.h"
10 #include "media/base/bit_reader.h"
11 #include "media/base/test_random.h"
12
13 // Entry point for LibFuzzer.
14 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
15 media::BitReader reader(data, base::checked_cast<int>(size));
16
17 // Need a simple random number generator to generate the number of bits to
18 // read/skip in a reproducible way (given the same |data|). Using Hash() to
19 // ensure the seed varies significantly over minor changes in |data|.
20 media::TestRandom rnd(base::Hash(reinterpret_cast<const char*>(data), size));
21
22 // Read and skip through the data in |reader|.
23 while (reader.bits_available() > 0) {
24 if (rnd.Rand() & 1) {
25 // Read up to 64 bits. This may fail if there is not enough bits
26 // remaining, but it doesn't matter (testing for failures is also good).
27 uint64_t value;
28 if (!reader.ReadBits(rnd.Rand() % 64 + 1, &value))
29 break;
30 } else {
31 // Skip up to 128 bits. As above, this may fail.
32 if (!reader.SkipBits(rnd.Rand() % 128 + 1))
33 break;
34 }
35 }
36 return 0;
37 }
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