|
33 | 33 |
|
34 | 34 | namespace fuzzer {
|
35 | 35 | static const size_t kMaxUnitSizeToPrint = 256;
|
36 |
| -static const size_t TruncateMaxRuns = 1000; |
37 | 36 |
|
38 | 37 | thread_local bool Fuzzer::IsMyThread;
|
39 | 38 |
|
@@ -371,39 +370,22 @@ void Fuzzer::ShuffleCorpus(UnitVector *V) {
|
371 | 370 | }
|
372 | 371 |
|
373 | 372 | // Tries random prefixes of corpus items.
|
374 |
| -// Prefix length is chosen according to exponential distribution |
375 |
| -// to sample short lengths much more heavily. |
376 | 373 | void Fuzzer::TruncateUnits(std::vector<Unit> *NewCorpus) {
|
377 |
| - size_t MaxCorpusLen = 0; |
378 |
| - for (const auto &U : Corpus) |
379 |
| - MaxCorpusLen = std::max(MaxCorpusLen, U.size()); |
380 |
| - |
381 |
| - if (MaxCorpusLen <= 1) |
382 |
| - return; |
| 374 | + std::vector<double> Fractions = {0.25, 0.5, 0.75, 1.0}; |
383 | 375 |
|
384 |
| - // 50% of exponential distribution is Log[2]/lambda. |
385 |
| - // Choose lambda so that median is MaxCorpusLen / 2. |
386 |
| - double Lambda = 2.0 * log(2.0) / static_cast<double>(MaxCorpusLen); |
387 |
| - std::exponential_distribution<> Dist(Lambda); |
388 |
| - std::vector<double> Sizes; |
389 |
| - size_t TruncatePoints = std::max(1ul, TruncateMaxRuns / Corpus.size()); |
390 |
| - Sizes.reserve(TruncatePoints); |
391 |
| - for (size_t I = 0; I < TruncatePoints; ++I) { |
392 |
| - Sizes.push_back(Dist(MD.GetRand().Get_mt19937()) + 1); |
393 |
| - } |
394 |
| - std::sort(Sizes.begin(), Sizes.end()); |
395 |
| - |
396 |
| - for (size_t S : Sizes) { |
| 376 | + size_t TruncInputs = 0; |
| 377 | + for (double Fraction : Fractions) { |
397 | 378 | for (const auto &U : Corpus) {
|
398 |
| - if (S < U.size() && RunOne(U.data(), S)) { |
399 |
| - Unit U1(U.begin(), U.begin() + S); |
400 |
| - NewCorpus->push_back(U1); |
401 |
| - WriteToOutputCorpus(U1); |
402 |
| - PrintStatusForNewUnit(U1); |
403 |
| - } |
| 379 | + uint64_t S = MD.GetRand()(U.size() * Fraction); |
| 380 | + if (!S || !RunOne(U.data(), S)) |
| 381 | + continue; |
| 382 | + TruncInputs++; |
| 383 | + Unit U1(U.begin(), U.begin() + S); |
| 384 | + NewCorpus->push_back(U1); |
404 | 385 | }
|
405 | 386 | }
|
406 |
| - PrintStats("TRUNC "); |
| 387 | + if (TruncInputs) |
| 388 | + Printf("\tINFO TRUNC %zd units added to in-memory corpus\n", TruncInputs); |
407 | 389 | }
|
408 | 390 |
|
409 | 391 | void Fuzzer::ShuffleAndMinimize() {
|
|
0 commit comments