Skip to content

Commit 52f1df0

Browse files
committed
Recommit "[libFuzzer] Fix value-profile-load test."
value-profile-load.test needs adjustment with a mutator change in bb54bcf, which reverted as of now, but will be recommitted after landing this patch. This patch makes value-profile-load.test more friendly to (and aware of) the current value profiling strategy, which is based on the hamming as well as the absolute distance. To this end, this patch adjusts the set of input values that trigger an expected crash. More specifically, this patch now uses a single value 0x01effffe as a crashing input, because this value is close to values like {0x1ffffff, 0xffffff, ...}, which are very likely to be added to the corpus per the current hamming- and absolute-distance-based value profiling strategy. Note that previously the crashing input values were {1234567 * {1, 2, ...}, s.t. < INT_MAX}. Every byte in the chosen value 0x01effeef is intentionally different; this was to make it harder to find the value without the intermediate inputs added to the corpus by the value profiling strategy. Also note that LoadTest.cpp now uses a narrower condition (Size != 8) for initial pruning of inputs, effectively preventing libFuzzer from generating inputs longer than necessary and spending time on mutating such long inputs in the corpus - a functionality not meant to be tested by this specific test. Differential Revision: https://reviews.llvm.org/D86247
1 parent 3f8a0ec commit 52f1df0

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

compiler-rt/test/fuzzer/LoadTest.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
#include <cstring>
1010
#include <iostream>
1111

12-
static volatile int Sink;
13-
const int kArraySize = 1234567;
14-
int array[kArraySize];
12+
static volatile uint8_t Sink;
13+
const int kArraySize = 32505854; // 0x01effffe
14+
uint8_t array[kArraySize];
1515

1616
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
17-
if (Size < 8) return 0;
17+
if (Size != 8)
18+
return 0;
1819
uint64_t a = 0;
19-
memcpy(&a, Data, 8);
20+
memcpy(&a, Data, sizeof(a));
21+
a &= 0x1fffffff;
2022
Sink = array[a % (kArraySize + 1)];
2123
return 0;
2224
}
23-
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
CHECK: AddressSanitizer: global-buffer-overflow
22
RUN: %cpp_compiler %S/LoadTest.cpp -fsanitize-coverage=trace-gep -o %t-LoadTest
3-
RUN: not %run %t-LoadTest -seed=2 -use_cmp=0 -use_value_profile=1 -runs=20000000 2>&1 | FileCheck %s
3+
RUN: not %run %t-LoadTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=20000000 2>&1 | FileCheck %s

0 commit comments

Comments
 (0)