@@ -445,6 +445,24 @@ void Fuzzer::PrintPulseAndReportSlowInput(const uint8_t *Data, size_t Size) {
445445 }
446446}
447447
448+ static void WriteFeatureSetToFile (const std::string &FeaturesDir,
449+ const uint8_t Sha1[],
450+ const Vector<uint32_t > &FeatureSet) {
451+ if (FeaturesDir.empty () || FeatureSet.empty ()) return ;
452+ WriteToFile (reinterpret_cast <const uint8_t *>(FeatureSet.data ()),
453+ FeatureSet.size () * sizeof (FeatureSet[0 ]),
454+ DirPlusFile (FeaturesDir, Sha1ToString (Sha1)));
455+ Printf (" Features: %s\n " , Sha1ToString (Sha1).c_str ());
456+ }
457+
458+ static void RenameFeatureSetFile (const std::string &FeaturesDir,
459+ const std::string &OldFile,
460+ const std::string &NewFile) {
461+ if (FeaturesDir.empty ()) return ;
462+ RenameFile (DirPlusFile (FeaturesDir, OldFile),
463+ DirPlusFile (FeaturesDir, NewFile));
464+ }
465+
448466bool Fuzzer::RunOne (const uint8_t *Data, size_t Size, bool MayDeleteFile,
449467 InputInfo *II, bool *FoundUniqFeatures) {
450468 if (!Size)
@@ -469,15 +487,21 @@ bool Fuzzer::RunOne(const uint8_t *Data, size_t Size, bool MayDeleteFile,
469487 size_t NumNewFeatures = Corpus.NumFeatureUpdates () - NumUpdatesBefore;
470488 if (NumNewFeatures) {
471489 TPC.UpdateObservedPCs ();
472- Corpus.AddToCorpus ({Data, Data + Size}, NumNewFeatures, MayDeleteFile,
473- TPC.ObservedFocusFunction (), UniqFeatureSetTmp, DFT, II);
490+ auto NewII = Corpus.AddToCorpus ({Data, Data + Size}, NumNewFeatures,
491+ MayDeleteFile, TPC.ObservedFocusFunction (),
492+ UniqFeatureSetTmp, DFT, II);
493+ WriteFeatureSetToFile (Options.FeaturesDir , NewII->Sha1 ,
494+ NewII->UniqFeatureSet );
474495 return true ;
475496 }
476497 if (II && FoundUniqFeaturesOfII &&
477498 II->DataFlowTraceForFocusFunction .empty () &&
478499 FoundUniqFeaturesOfII == II->UniqFeatureSet .size () &&
479500 II->U .size () > Size) {
501+ auto OldFeaturesFile = Sha1ToString (II->Sha1 );
480502 Corpus.Replace (II, {Data, Data + Size});
503+ RenameFeatureSetFile (Options.FeaturesDir , OldFeaturesFile,
504+ Sha1ToString (II->Sha1 ));
481505 return true ;
482506 }
483507 return false ;
0 commit comments