Commit 33029b89 authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

Remove base::Hash() usage in fuzzers.

base::Hash() is deprecated and is being replaced by base::FastHash().
The output of base::FastHash() is only fixed within the lifetime of a
single process, so if the code depends on the mapping of inputs to hash
outputs not changing over time, base::PersistentHash() must be used
instead.

Bug: 1025358
Change-Id: I88f09613aa5b099517de6079f857fbf0f6d1d50f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1954453Reviewed-by: default avatarOliver Chang <ochang@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738247}
parent f4ba2ef4
...@@ -5,19 +5,29 @@ ...@@ -5,19 +5,29 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "base/hash/hash.h" #include "base/containers/buffer_iterator.h"
#include "base/containers/span.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "media/base/bit_reader.h" #include "media/base/bit_reader.h"
#include "media/base/test_random.h" #include "media/base/test_random.h"
// Entry point for LibFuzzer. // Entry point for LibFuzzer.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
media::BitReader reader(data, base::checked_cast<int>(size)); base::BufferIterator<const uint8_t> iterator(data, size);
const uint32_t* random_seed = iterator.Object<uint32_t>();
if (!random_seed)
return 0;
// Need a simple random number generator to generate the number of bits to // Need a simple random number generator to generate the number of bits to
// read/skip in a reproducible way (given the same |data|). Using Hash() to // read/skip in a reproducible way (given the same |data|).
// ensure the seed varies significantly over minor changes in |data|. media::TestRandom rnd(*random_seed);
media::TestRandom rnd(base::Hash(data, size));
base::span<const uint8_t> remaining =
iterator.Span<uint8_t>(iterator.total_size() - iterator.position());
media::BitReader reader(remaining.data(),
base::checked_cast<int>(remaining.size()));
// Read and skip through the data in |reader|. // Read and skip through the data in |reader|.
while (reader.bits_available() > 0) { while (reader.bits_available() > 0) {
......
...@@ -5,10 +5,12 @@ ...@@ -5,10 +5,12 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "base/containers/span.h"
#include "base/hash/hash.h" #include "base/hash/hash.h"
// Entry point for LibFuzzer. // Entry point for LibFuzzer.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
base::Hash(data, size); base::PersistentHash(base::make_span(data, size));
base::FastHash(base::make_span(data, size));
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment