F.RereadOutputCorpus();
for (auto &inp : *Inputs)
if (inp != Options.OutputCorpus)
- F.ReadDir(inp, nullptr);
+ F.ReadDir(inp, nullptr, Options.MaxLen);
if (F.CorpusSize() == 0)
F.AddToCorpus(Unit()); // Can't fuzz empty corpus, so add an empty input.
return V;
}
-Unit FileToVector(const std::string &Path) {
+Unit FileToVector(const std::string &Path, size_t MaxSize) {
std::ifstream T(Path);
if (!T) {
Printf("No such directory: %s; exiting\n", Path.c_str());
exit(1);
}
+ if (MaxSize) {
+ Unit Res(MaxSize);
+ T.read(reinterpret_cast<char*>(Res.data()), MaxSize);
+ Res.resize(T.gcount());
+ return Res;
+ }
return Unit((std::istreambuf_iterator<char>(T)),
std::istreambuf_iterator<char>());
}
}
void ReadDirToVectorOfUnits(const char *Path, std::vector<Unit> *V,
- long *Epoch) {
+ long *Epoch, size_t MaxSize) {
long E = Epoch ? *Epoch : 0;
auto Files = ListFilesInDir(Path, Epoch);
for (size_t i = 0; i < Files.size(); i++) {
auto &X = Files[i];
auto FilePath = DirPlusFile(Path, X);
if (Epoch && GetEpoch(FilePath) < E) continue;
- if ((i % 1000) == 0 && i)
+ if ((i & (i - 1)) == 0 && i >= 1024)
Printf("Loaded %zd/%zd files from %s\n", i, Files.size(), Path);
- V->push_back(FileToVector(FilePath));
+ V->push_back(FileToVector(FilePath, MaxSize));
}
}
bool IsFile(const std::string &Path);
std::string FileToString(const std::string &Path);
-Unit FileToVector(const std::string &Path);
+Unit FileToVector(const std::string &Path, size_t MaxSize = 0);
void ReadDirToVectorOfUnits(const char *Path, std::vector<Unit> *V,
- long *Epoch);
+ long *Epoch, size_t MaxSize);
void WriteToFile(const Unit &U, const std::string &Path);
void CopyFileToErr(const std::string &Path);
// Returns "Dir/FileName" or equivalent for the current OS.
void InitializeTraceState();
void AssignTaintLabels(uint8_t *Data, size_t Size);
size_t CorpusSize() const { return Corpus.size(); }
- void ReadDir(const std::string &Path, long *Epoch) {
+ void ReadDir(const std::string &Path, long *Epoch, size_t MaxSize) {
Printf("Loading corpus: %s\n", Path.c_str());
- ReadDirToVectorOfUnits(Path.c_str(), &Corpus, Epoch);
+ ReadDirToVectorOfUnits(Path.c_str(), &Corpus, Epoch, MaxSize);
}
void RereadOutputCorpus();
// Save the current corpus to OutputCorpus.
return;
std::vector<Unit> AdditionalCorpus;
ReadDirToVectorOfUnits(Options.OutputCorpus.c_str(), &AdditionalCorpus,
- &EpochOfLastReadOfOutputCorpus);
+ &EpochOfLastReadOfOutputCorpus, Options.MaxLen);
if (Corpus.empty()) {
Corpus = AdditionalCorpus;
return;
return;
}
auto InitialCorpusDir = Corpora[0];
- ReadDir(InitialCorpusDir, nullptr);
+ ReadDir(InitialCorpusDir, nullptr, Options.MaxLen);
Printf("Merge: running the initial corpus '%s' of %d units\n",
InitialCorpusDir.c_str(), Corpus.size());
for (auto &U : Corpus)
size_t NumMerged = 0;
for (auto &C : ExtraCorpora) {
Corpus.clear();
- ReadDir(C, nullptr);
+ ReadDir(C, nullptr, Options.MaxLen);
Printf("Merge: merging the extra corpus '%s' of %zd units\n", C.c_str(),
Corpus.size());
for (auto &U : Corpus) {