diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-07-19 07:02:10 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-07-19 07:02:10 +0000 | 
| commit | 93c91e39b29142dec1d03a30df9f6e757f56c193 (patch) | |
| tree | 33a9b014a327e64450b3c9ed46d8c5bdb78ad345 /lib/Fuzzer/FuzzerCorpus.h | |
| parent | ca089b24d48ef6fa8da2d0bb8c25bb802c4a95c0 (diff) | |
Notes
Diffstat (limited to 'lib/Fuzzer/FuzzerCorpus.h')
| -rw-r--r-- | lib/Fuzzer/FuzzerCorpus.h | 40 | 
1 files changed, 13 insertions, 27 deletions
diff --git a/lib/Fuzzer/FuzzerCorpus.h b/lib/Fuzzer/FuzzerCorpus.h index 218ae5b6ac4d4..bae0aea78f13a 100644 --- a/lib/Fuzzer/FuzzerCorpus.h +++ b/lib/Fuzzer/FuzzerCorpus.h @@ -34,7 +34,8 @@ struct InputInfo {    size_t NumExecutedMutations = 0;    size_t NumSuccessfullMutations = 0;    bool MayDeleteFile = false; -  std::vector<uint32_t> FeatureSet; +  bool Reduced = false; +  std::vector<uint32_t> UniqFeatureSet;  };  class InputCorpus { @@ -79,7 +80,8 @@ class InputCorpus {      II.U = U;      II.NumFeatures = NumFeatures;      II.MayDeleteFile = MayDeleteFile; -    II.FeatureSet = FeatureSet; +    II.UniqFeatureSet = FeatureSet; +    std::sort(II.UniqFeatureSet.begin(), II.UniqFeatureSet.end());      ComputeSHA1(U.data(), U.size(), II.Sha1);      Hashes.insert(Sha1ToString(II.Sha1));      UpdateCorpusDistribution(); @@ -117,34 +119,21 @@ class InputCorpus {          Printf("%s sz=%zd ", Sha1ToString(II->Sha1).c_str(), II->U.size());          PrintUnit(II->U);          Printf(" "); -        PrintFeatureSet(II->FeatureSet); +        PrintFeatureSet(II->UniqFeatureSet);          Printf("\n");        }        i++;      }    } -  // If FeatureSet is that same as in II, replace II->U with {Data,Size}. -  bool TryToReplace(InputInfo *II, const uint8_t *Data, size_t Size, -                    const std::vector<uint32_t> &FeatureSet) { -    if (II->U.size() > Size && II->FeatureSet.size() && -        II->FeatureSet == FeatureSet) { -      if (FeatureDebug) -        Printf("Replace: %zd => %zd\n", II->U.size(), Size); -      Replace(II, {Data, Data + Size}); -      PrintCorpus(); -      return true; -    } -    return false; -  } -    void Replace(InputInfo *II, const Unit &U) { -    assert(II->U.size()); +    assert(II->U.size() > U.size());      Hashes.erase(Sha1ToString(II->Sha1));      DeleteFile(*II);      ComputeSHA1(U.data(), U.size(), II->Sha1);      Hashes.insert(Sha1ToString(II->Sha1));      II->U = U; +    II->Reduced = true;    }    bool HasUnit(const Unit &U) { return Hashes.count(Hash(U)); } @@ -198,7 +187,7 @@ class InputCorpus {        Printf("EVICTED %zd\n", Idx);    } -  void AddFeature(size_t Idx, uint32_t NewSize, bool Shrink) { +  bool AddFeature(size_t Idx, uint32_t NewSize, bool Shrink) {      assert(NewSize);      Idx = Idx % kFeatureSetSize;      uint32_t OldSize = GetFeature(Idx); @@ -218,8 +207,9 @@ class InputCorpus {          Printf("ADD FEATURE %zd sz %d\n", Idx, NewSize);        SmallestElementPerFeature[Idx] = Inputs.size();        InputSizesPerFeature[Idx] = NewSize; -      CountingFeatures = true; +      return true;      } +    return false;    }    size_t NumFeatures() const { return NumAddedFeatures; } @@ -238,7 +228,6 @@ private:    size_t GetFeature(size_t Idx) const { return InputSizesPerFeature[Idx]; }    void ValidateFeatureSet() { -    if (!CountingFeatures) return;      if (FeatureDebug)        PrintFeatureSet();      for (size_t Idx = 0; Idx < kFeatureSetSize; Idx++) @@ -256,14 +245,12 @@ private:    // Must be called whenever the corpus or unit weights are changed.    void UpdateCorpusDistribution() {      size_t N = Inputs.size(); +    assert(N);      Intervals.resize(N + 1);      Weights.resize(N);      std::iota(Intervals.begin(), Intervals.end(), 0); -    if (CountingFeatures) -      for (size_t i = 0; i < N; i++) -        Weights[i] = Inputs[i]->NumFeatures * (i + 1); -    else -      std::iota(Weights.begin(), Weights.end(), 1); +    for (size_t i = 0; i < N; i++) +      Weights[i] = Inputs[i]->NumFeatures * (i + 1);      CorpusDistribution = std::piecewise_constant_distribution<double>(          Intervals.begin(), Intervals.end(), Weights.begin());    } @@ -275,7 +262,6 @@ private:    std::unordered_set<std::string> Hashes;    std::vector<InputInfo*> Inputs; -  bool CountingFeatures = false;    size_t NumAddedFeatures = 0;    size_t NumUpdatedFeatures = 0;    uint32_t InputSizesPerFeature[kFeatureSetSize];  | 
