Skip to content

Commit

Permalink
reduce the scope of the fuzzer (#846)
Browse files Browse the repository at this point in the history
* reduce the scope of the fuzzer

* lint
  • Loading branch information
lemire authored and anonrig committed Jan 22, 2025
1 parent a0563a3 commit 57d3866
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions fuzz/url_pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,32 @@
#include "ada.cpp"
#include "ada.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
std::string bytesToAlphanumeric(const std::string& source) {
static const char alphanumeric[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";

std::string result;
result.reserve(source.size());

for (char byte : source) {
int index = static_cast<unsigned char>(byte) % (sizeof(alphanumeric) - 1);
result.push_back(alphanumeric[index]);
}

return result;
}

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
FuzzedDataProvider fdp(data, size);
std::string source = fdp.ConsumeRandomLengthString(50);
std::string base_source = fdp.ConsumeRandomLengthString(50);
// We do not want to trigger arbitrary regex matching.
std::string source =
"/" + bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50)) + "/" +
bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50));
std::string base_source =
"/" + bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50)) + "/" +
bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50));

// Without base or options
auto result = ada::parse_url_pattern(source, nullptr, nullptr);
Expand Down

0 comments on commit 57d3866

Please sign in to comment.