diff --git a/test/common/common/BUILD b/test/common/common/BUILD index d72fea4b65215..4714f1ff5c721 100644 --- a/test/common/common/BUILD +++ b/test/common/common/BUILD @@ -55,6 +55,13 @@ 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", + deps = ["//source/common/common:hash_lib"], +) + envoy_cc_test( name = "cleanup_test", srcs = ["cleanup_test.cc"], diff --git a/test/common/common/hash_corpus/example b/test/common/common/hash_corpus/example new file mode 100644 index 0000000000000..95d09f2b10159 --- /dev/null +++ b/test/common/common/hash_corpus/example @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/test/common/common/hash_fuzz_test.cc b/test/common/common/hash_fuzz_test.cc new file mode 100644 index 0000000000000..a4b3f6c032a30 --- /dev/null +++ b/test/common/common/hash_fuzz_test.cc @@ -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(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(buf) % len; + const std::string key = input.substr(0, split_point); + const std::string value = input.substr(split_point); + StringMap map; + map[key] = value; + map.find(key); + } +} + +} // namespace +} // namespace Fuzz +} // namespace Envoy