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 // Simple test for a fuzzer. The fuzzer must find repeated bytes.
6 #include <assert.h>
7 #include <cstddef>
8 #include <cstdint>
9 #include <cstdlib>
10 #include <iostream>
11 #include <ostream>
12 
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)13 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
14   assert(Data);
15   // Looking for AAAAAAAAAAAAAAAAAAAAAA or some such.
16   size_t CurA = 0, MaxA = 0;
17   for (size_t i = 0; i < Size; i++) {
18     // Make sure there are no conditionals in the loop so that
19     // coverage can't help the fuzzer.
20     int EQ = Data[i] == 'A';
21     CurA = EQ * (CurA + 1);
22     int GT = CurA > MaxA;
23     MaxA = GT * CurA + (!GT) * MaxA;
24   }
25   if (MaxA >= 20) {
26     std::cout << "BINGO; Found the target (Max: " << MaxA << "), exiting\n"
27               << std::flush;
28     exit(0);
29   }
30   return 0;
31 }
32 
33