From 3c7f09ce89f0bdfbfc57ec935c41d93c19bbed92 Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Mon, 9 Dec 2024 11:31:32 -0800 Subject: [PATCH] Use the desired `Mutate()` in the LLVM fuzzer wrapper domain. Otherwise `ContainerOfImplBase::Mutate()` will be used instead of `ArbitraryByteVector::Mutate()`, which handles the custom mutator logic. PiperOrigin-RevId: 704359343 --- fuzztest/internal/domains/container_of_impl.h | 42 ++++++++++++------- fuzztest/llvm_fuzzer_wrapper.cc | 5 ++- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/fuzztest/internal/domains/container_of_impl.h b/fuzztest/internal/domains/container_of_impl.h index 6e30c6e6..3ef62f8b 100644 --- a/fuzztest/internal/domains/container_of_impl.h +++ b/fuzztest/internal/domains/container_of_impl.h @@ -74,12 +74,11 @@ using ContainerOfImplBaseCorpusType = std::conditional_t< std::list>, ValueType>; // Common base for container domains. Provides common APIs. -template -class ContainerOfImplBase : public domain_implementor::DomainBase< - Derived, ExtractTemplateParameter<0, Derived>, - ContainerOfImplBaseCorpusType> { - using InnerDomainT = ExtractTemplateParameter<1, Derived>; - +template , + typename InnerDomainT = ExtractTemplateParameter<1, Derived>> +class ContainerOfImplBase + : public domain_implementor::DomainBase< + Derived, T, ContainerOfImplBaseCorpusType> { public: using ContainerOfImplBase::DomainBase::has_custom_corpus_type; using typename ContainerOfImplBase::DomainBase::corpus_type; @@ -124,7 +123,6 @@ class ContainerOfImplBase : public domain_implementor::DomainBase< const bool can_use_memory_dict = !only_shrink && container_has_memory_dict && can_change && metadata.cmp_tables != nullptr; - const int action_count = can_shrink + can_grow + can_change + can_use_memory_dict; if (action_count == 0) return; @@ -341,11 +339,13 @@ class ContainerOfImplBase : public domain_implementor::DomainBase< InnerDomainT Inner() const { return inner_; } - template + // Needed for `CopyConstraintsFrom`. + template friend class ContainerOfImplBase; - template - void CopyConstraintsFrom(const ContainerOfImplBase& other) { + template + void CopyConstraintsFrom(const ContainerOfImplBase& other) { min_size_ = other.min_size_; max_size_ = other.max_size_; } @@ -524,16 +524,17 @@ Please verify that the inner domain can provide enough values. } }; -template -class SequenceContainerOfImpl - : public ContainerOfImplBase> { - using Base = typename SequenceContainerOfImpl::ContainerOfImplBase; +template , + typename InnerDomain = ExtractTemplateParameter<1, Derived>> +class SequenceContainerOfImplBase + : public ContainerOfImplBase { + using Base = typename SequenceContainerOfImplBase::ContainerOfImplBase; public: using typename Base::corpus_type; - SequenceContainerOfImpl() = default; - explicit SequenceContainerOfImpl(InnerDomain inner) + SequenceContainerOfImplBase() = default; + explicit SequenceContainerOfImplBase(InnerDomain inner) : Base(std::move(inner)) {} corpus_type Init(absl::BitGenRef prng) { @@ -582,6 +583,15 @@ class SequenceContainerOfImpl } }; +template +class SequenceContainerOfImpl : public SequenceContainerOfImplBase< + SequenceContainerOfImpl> { + using Base = typename SequenceContainerOfImpl::SequenceContainerOfImplBase; + + public: + using Base::Base; +}; + template using ContainerOfImpl = std::conditional_t, diff --git a/fuzztest/llvm_fuzzer_wrapper.cc b/fuzztest/llvm_fuzzer_wrapper.cc index dc6a3638..b28d1f18 100644 --- a/fuzztest/llvm_fuzzer_wrapper.cc +++ b/fuzztest/llvm_fuzzer_wrapper.cc @@ -177,8 +177,9 @@ extern "C" size_t LLVMFuzzerMutate(uint8_t* data, size_t size, } class ArbitraryByteVector - : public fuzztest::internal::SequenceContainerOfImpl< - std::vector, fuzztest::internal::ArbitraryImpl> { + : public fuzztest::internal::SequenceContainerOfImplBase< + ArbitraryByteVector, std::vector, + fuzztest::internal::ArbitraryImpl> { using Base = typename ArbitraryByteVector::ContainerOfImplBase; public: