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