Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/common/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ envoy_cc_fuzz_test(
deps = ["//source/common/common:utility_lib"],
)

envoy_cc_fuzz_test(
name = "hash_fuzz_test",
srcs = ["hash_fuzz_test.cc"],
corpus = "hash_corpus",
# Fuzzer is stable, no bugs, simple test target; avoid emitting CO2.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider letting it run for some amount of time on ClusterFuzz? What about catching regressions as we bump our version dependency?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could definitely do, I thought about following this PR with some regressions from local bazel/libfuzzer runs since it's relatively low risk, but I'll remove that tag and let it run!

tags = ["no_fuzz"],
deps = ["//source/common/common:hash_lib"],
)

envoy_cc_test(
name = "cleanup_test",
srcs = ["cleanup_test.cc"],
Expand Down
1 change: 1 addition & 0 deletions test/common/common/hash_corpus/example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
29 changes: 29 additions & 0 deletions test/common/common/hash_fuzz_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "common/common/hash.h"

#include "test/fuzz/fuzz_runner.h"

#include "absl/strings/string_view.h"

namespace Envoy {
namespace Fuzz {
namespace {

DEFINE_FUZZER(const uint8_t* buf, size_t len) {
const std::string input(reinterpret_cast<const char*>(buf), len);
{ HashUtil::xxHash64(input); }
{ HashUtil::djb2CaseInsensitiveHash(input); }
{ MurmurHash::murmurHash2_64(input); }
if (len > 0) {
// Split the input string into two parts to make a key-value pair.
const size_t split_point = *reinterpret_cast<const uint8_t*>(buf) % len;
const std::string key = input.substr(0, split_point);
const std::string value = input.substr(split_point);
StringMap<std::string> map;
map[key] = value;
map.find(key);
}
}

} // namespace
} // namespace Fuzz
} // namespace Envoy