fuzz: improvements (#2400)

Create the zip file with all the traces only once.

Add a new fuzzer to test "shoco" compression algorithm
This commit is contained in:
Ivan Nardi
2024-04-20 18:15:23 +02:00
committed by GitHub
parent 905120588b
commit ef89183469
9 changed files with 62 additions and 34 deletions
+2 -5
View File
@@ -8,7 +8,7 @@
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
FuzzedDataProvider fuzzed_data(data, size);
u_int16_t i, rc, num_iteration, data_len, is_added = 0;
u_int16_t value16, i, rc, num_iteration, data_len, is_added = 0;
std::vector<char>value_added;
ndpi_str_hash *h = NULL;
@@ -30,7 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
data_len = fuzzed_data.ConsumeIntegralInRange(0, 127);
std::vector<char>data = fuzzed_data.ConsumeBytes<char>(data_len);
rc = ndpi_hash_add_entry(&h, data.data(), data.size(), (u_int16_t)i);
rc = ndpi_hash_add_entry(&h, data.data(), data.size(), i);
/* Keep one random entry really added */
if (rc == 0 && fuzzed_data.ConsumeBool()) {
value_added = data;
@@ -41,8 +41,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
/* "Random" search */
num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
for (i = 0; i < num_iteration; i++) {
u_int16_t value16;
data_len = fuzzed_data.ConsumeIntegralInRange(0, 127);
std::vector<char>data = fuzzed_data.ConsumeBytes<char>(data_len);
@@ -50,7 +48,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
}
/* Search of an added entry */
if (is_added) {
u_int16_t value16;
ndpi_hash_find_entry(h, value_added.data(), value_added.size(), &value16);
}