From f8195f5b828b094b375fb30ea447540dbef228ec Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Mon, 18 Nov 2024 13:51:28 -0800 Subject: [PATCH] Tolerate bad mutate inputs in compatibility mode. PiperOrigin-RevId: 697746529 --- fuzztest/internal/compatibility_mode.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fuzztest/internal/compatibility_mode.cc b/fuzztest/internal/compatibility_mode.cc index 59d057fe..dc979dcc 100644 --- a/fuzztest/internal/compatibility_mode.cc +++ b/fuzztest/internal/compatibility_mode.cc @@ -136,12 +136,15 @@ std::string FuzzTestExternalEngineAdaptor::MutateData(absl::string_view data, unsigned int seed) { auto& impl = GetFuzzerImpl(); typename FuzzerImpl::PRNG prng(seed); - const auto input = [&]() -> decltype(impl.TryParse(data)) { - if (!IsEnginePlaceholderInput(data)) { - return impl.TryParse(data); - } - return impl.params_domain_.Init(prng); - }(); + std::optional input = std::nullopt; + if (!IsEnginePlaceholderInput(data)) { + auto parse_result = impl.TryParse(data); + if (parse_result.ok()) input = *std::move(parse_result); + } + if (!input) input = impl.params_domain_.Init(prng); + FUZZTEST_INTERNAL_CHECK( + input.has_value(), + "Both parsing and initiating the mutation input has failed."); constexpr int kNumAttempts = 10; std::string result; for (int i = 0; i < kNumAttempts; ++i) {