1// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2// See https://llvm.org/LICENSE.txt for license information.
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5// The fuzzer must find several constants with swapped bytes.
6#include <cstdint>
7#include <cstdio>
8#include <cstdlib>
9#include <cstring>
10
11extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
12 if (Size < 14) return 0;
13 uint64_t x = 0;
14 uint32_t y = 0;
15 uint32_t z = 0;
16 memcpy(&x, Data, sizeof(x));
17 memcpy(&y, Data + Size / 2, sizeof(y));
18 memcpy(&z, Data + Size - sizeof(z), sizeof(z));
19
20 x = __builtin_bswap64(x);
21 y = __builtin_bswap32(y);
22 z = __builtin_bswap32(z);
23 const bool k32bit = sizeof(void*) == 4;
24
25 if ((k32bit || x == 0x46555A5A5A5A5546ULL) &&
26 z == 0x4F4B &&
27 y == 0x66757A7A &&
28 true
29 ) {
30 if (Data[Size - 5] == 'z') {
31 fprintf(stderr, "BINGO; Found the target\n");
32 exit(1);
33 }
34 }
35 return 0;
36}
37