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.
6// Here the target has a shallow OOM bug and a deeper crash.
7// Make sure we can find the crash while ignoring OOMs.
8#include <cstddef>
9#include <cstdint>
10
11static volatile int *Sink;
12static volatile int *Zero;
13
14extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
15 if (Size >= 3 && Data[0] == 'O' && Data[1] == 'O' && Data[2] == 'M')
16 Sink = new int[1 << 28]; // instant OOM with -rss_limit_mb=128.
17 if (Size >= 4 && Data[0] == 'F' && Data[1] == 'U' && Data[2] == 'Z' &&
18 Data[3] == 'Z') // a bit deeper crash.
19 *Zero = 42;
20 return 0;
21}
22
23

source code of compiler-rt/test/fuzzer/ShallowOOMDeepCrash.cpp