Commit 238c19e1 by Jamie Madill Committed by Commit Bot

Add fuzzer for xxHash.

Local testing did not turn up any crashes. Bug: angleproject:2983 Change-Id: I5e87ed0768e5bc4454c1a896f96d09ddd92baf44 Reviewed-on: https://chromium-review.googlesource.com/c/1458656Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 38833111
...@@ -30,6 +30,7 @@ if (!build_with_chromium) { ...@@ -30,6 +30,7 @@ if (!build_with_chromium) {
deps = [ deps = [
":angle_shader_translator", ":angle_shader_translator",
":translator_fuzzer", ":translator_fuzzer",
":xxhash_fuzzer",
"//samples:all", "//samples:all",
"//src/tests:all", "//src/tests:all",
] ]
...@@ -208,6 +209,15 @@ angle_source_set("xxhash") { ...@@ -208,6 +209,15 @@ angle_source_set("xxhash") {
configs -= [ "${angle_root}:extra_warnings" ] configs -= [ "${angle_root}:extra_warnings" ]
} }
fuzzer_test("xxhash_fuzzer") {
sources = [
"src/common/third_party/xxhash/xxhash_fuzzer.cpp",
]
deps = [
":xxhash",
]
}
angle_static_library("angle_common") { angle_static_library("angle_common") {
sources = libangle_common_sources sources = libangle_common_sources
......
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// xxHash Fuzzer test:
// Integration with Chromium's libfuzzer for xxHash.
#include <cstddef>
#include <cstdint>
#include <cstring>
#include "xxhash.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
#if !defined(XXH_NO_LONG_LONG)
// Test 64-bit hash.
size_t seedSize64 = sizeof(unsigned long long);
if (size < seedSize64)
{
XXH64(data, size, 0ull);
}
else
{
unsigned long long seed64;
memcpy(&seed64, data, seedSize64);
XXH64(&data[seedSize64], size - seedSize64, seed64);
}
#endif // !defined(XXH_NO_LONG_LONG)
// Test 32-bit hash.
size_t seedSize32 = sizeof(unsigned int);
if (size < seedSize32)
{
XXH64(data, size, 0ull);
}
else
{
unsigned long long seed32;
memcpy(&seed32, data, seedSize32);
XXH32(&data[seedSize32], size - seedSize32, seed32);
}
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