| 520 | } |
| 521 | |
| 522 | bool Fuzzer::RunOne(const uint8_t *Data, size_t Size, bool MayDeleteFile, |
| 523 | InputInfo *II, bool ForceAddToCorpus, |
| 524 | bool *FoundUniqFeatures) { |
| 525 | if (!Size) |
| 526 | return false; |
| 527 | // Largest input length should be INT_MAX. |
| 528 | assert(Size < std::numeric_limits<uint32_t>::max()); |
| 529 | |
| 530 | if(!ExecuteCallback(Data, Size)) return false; |
| 531 | auto TimeOfUnit = duration_cast<microseconds>(UnitStopTime - UnitStartTime); |
| 532 | |
| 533 | UniqFeatureSetTmp.clear(); |
| 534 | size_t FoundUniqFeaturesOfII = 0; |
| 535 | size_t NumUpdatesBefore = Corpus.NumFeatureUpdates(); |
| 536 | TPC.CollectFeatures([&](uint32_t Feature) { |
| 537 | if (Corpus.AddFeature(Feature, static_cast<uint32_t>(Size), Options.Shrink)) |
| 538 | UniqFeatureSetTmp.push_back(Feature); |
| 539 | if (Options.Entropic) |
| 540 | Corpus.UpdateFeatureFrequency(II, Feature); |
| 541 | if (Options.ReduceInputs && II && !II->NeverReduce) |
| 542 | if (std::binary_search(II->UniqFeatureSet.begin(), |
| 543 | II->UniqFeatureSet.end(), Feature)) |
| 544 | FoundUniqFeaturesOfII++; |
| 545 | }); |
| 546 | if (FoundUniqFeatures) |
| 547 | *FoundUniqFeatures = FoundUniqFeaturesOfII; |
| 548 | PrintPulseAndReportSlowInput(Data, Size); |
| 549 | size_t NumNewFeatures = Corpus.NumFeatureUpdates() - NumUpdatesBefore; |
| 550 | if (NumNewFeatures || ForceAddToCorpus) { |
| 551 | TPC.UpdateObservedPCs(); |
| 552 | auto NewII = |
| 553 | Corpus.AddToCorpus({Data, Data + Size}, NumNewFeatures, MayDeleteFile, |
| 554 | TPC.ObservedFocusFunction(), ForceAddToCorpus, |
| 555 | TimeOfUnit, UniqFeatureSetTmp, DFT, II); |
| 556 | WriteFeatureSetToFile(Options.FeaturesDir, Sha1ToString(NewII->Sha1), |
| 557 | NewII->UniqFeatureSet); |
| 558 | WriteEdgeToMutationGraphFile(Options.MutationGraphFile, NewII, II, |
| 559 | MD.MutationSequence()); |
| 560 | return true; |
| 561 | } |
| 562 | if (II && FoundUniqFeaturesOfII && |
| 563 | II->DataFlowTraceForFocusFunction.empty() && |
| 564 | FoundUniqFeaturesOfII == II->UniqFeatureSet.size() && |
| 565 | II->U.size() > Size) { |
| 566 | auto OldFeaturesFile = Sha1ToString(II->Sha1); |
| 567 | Corpus.Replace(II, {Data, Data + Size}, TimeOfUnit); |
| 568 | RenameFeatureSetFile(Options.FeaturesDir, OldFeaturesFile, |
| 569 | Sha1ToString(II->Sha1)); |
| 570 | return true; |
| 571 | } |
| 572 | return false; |
| 573 | } |
| 574 | |
| 575 | void Fuzzer::TPCUpdateObservedPCs() { TPC.UpdateObservedPCs(); } |
| 576 |
nothing calls this directly
no test coverage detected