1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // xxHash Fuzzer test:
7 // Integration with Chromium's libfuzzer for xxHash.
8
9 #include <cstddef>
10 #include <cstdint>
11 #include <cstring>
12
13 #include "xxhash.h"
14
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)15 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
16 {
17 #if !defined(XXH_NO_LONG_LONG)
18 // Test 64-bit hash.
19 size_t seedSize64 = sizeof(unsigned long long);
20 if (size < seedSize64)
21 {
22 XXH64(data, size, 0ull);
23 }
24 else
25 {
26 unsigned long long seed64;
27 memcpy(&seed64, data, seedSize64);
28 XXH64(&data[seedSize64], size - seedSize64, seed64);
29 }
30 #endif // !defined(XXH_NO_LONG_LONG)
31
32 // Test 32-bit hash.
33 size_t seedSize32 = sizeof(unsigned int);
34 if (size < seedSize32)
35 {
36 XXH64(data, size, 0ull);
37 }
38 else
39 {
40 unsigned long long seed32;
41 memcpy(&seed32, data, seedSize32);
42 XXH32(&data[seedSize32], size - seedSize32, seed32);
43 }
44
45 return 0;
46 }
47