@@ -471,14 +471,21 @@ int MinimizeCrashInputInternalStep(Fuzzer *F, InputCorpus *Corpus) {
471
471
return 0 ;
472
472
}
473
473
474
- // This is just a sceleton of an experimental -fork=1 feature.
474
+ // This is just a skeleton of an experimental -fork=1 feature.
475
475
void FuzzWithFork (const FuzzingOptions &Options,
476
476
const Vector<std::string> &Args,
477
477
const Vector<std::string> &Corpora) {
478
478
auto CFPath = TempPath (" .fork" );
479
479
Printf (" INFO: -fork=1: doing fuzzing in a separate process in order to "
480
480
" be more resistant to crashes, timeouts, and OOMs\n " );
481
- auto Files = CrashResistantMerge (Args, Corpora, CFPath);
481
+
482
+
483
+ Vector<SizedFile> Corpus;
484
+ for (auto &Dir : Corpora)
485
+ GetSizedFilesFromDir (Dir, &Corpus);
486
+ std::sort (Corpus.begin (), Corpus.end ());
487
+
488
+ auto Files = CrashResistantMerge (Args, {}, Corpus, CFPath);
482
489
Printf (" INFO: -fork=1: seed corpus analyzed, %zd seeds chosen, starting to "
483
490
" fuzz in separate processes\n " , Files.size ());
484
491
@@ -500,6 +507,31 @@ void FuzzWithFork(const FuzzingOptions &Options,
500
507
exit (0 );
501
508
}
502
509
510
+ void Merge (Fuzzer *F, FuzzingOptions &Options, const Vector<std::string> &Args,
511
+ const Vector<std::string> &Corpora, const char *CFPathOrNull) {
512
+ if (Corpora.size () < 2 ) {
513
+ Printf (" INFO: Merge requires two or more corpus dirs\n " );
514
+ exit (0 );
515
+ }
516
+
517
+ Vector<SizedFile> OldCorpus, NewCorpus;
518
+ GetSizedFilesFromDir (Corpora[0 ], &OldCorpus);
519
+ for (size_t i = 1 ; i < Corpora.size (); i++)
520
+ GetSizedFilesFromDir (Corpora[i], &NewCorpus);
521
+ std::sort (OldCorpus.begin (), OldCorpus.end ());
522
+ std::sort (NewCorpus.begin (), NewCorpus.end ());
523
+
524
+ std::string CFPath = CFPathOrNull ? CFPathOrNull : TempPath (" .txt" );
525
+ auto Files = CrashResistantMerge (Args, OldCorpus, NewCorpus, CFPath);
526
+ for (auto &Path : Files)
527
+ F->WriteToOutputCorpus (FileToVector (Path, Options.MaxLen ));
528
+ // We are done, delete the control file if it was a temporary one.
529
+ if (!Flags.merge_control_file )
530
+ RemoveFile (CFPath);
531
+
532
+ exit (0 );
533
+ }
534
+
503
535
int AnalyzeDictionary (Fuzzer *F, const Vector<Unit>& Dict,
504
536
UnitVector& Corpus) {
505
537
Printf (" Started dictionary minimization (up to %d tests)\n " ,
@@ -730,22 +762,8 @@ int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) {
730
762
if (Flags.fork )
731
763
FuzzWithFork (Options, Args, *Inputs);
732
764
733
- if (Flags.merge ) {
734
- if (Inputs->size () < 2 ) {
735
- Printf (" INFO: Merge requires two or more corpus dirs\n " );
736
- exit (0 );
737
- }
738
- std::string CFPath =
739
- Flags.merge_control_file ? Flags.merge_control_file : TempPath (" .txt" );
740
- auto Files = CrashResistantMerge (Args, *Inputs, CFPath);
741
- for (auto &Path : Files)
742
- F->WriteToOutputCorpus (FileToVector (Path, Options.MaxLen ));
743
- // We are done, delete the control file if it was a temporary one.
744
- if (!Flags.merge_control_file )
745
- RemoveFile (CFPath);
746
-
747
- exit (0 );
748
- }
765
+ if (Flags.merge )
766
+ Merge (F, Options, Args, *Inputs, Flags.merge_control_file );
749
767
750
768
if (Flags.merge_inner ) {
751
769
const size_t kDefaultMaxMergeLen = 1 << 20 ;
0 commit comments