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 #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 } | |
OLD | NEW |