2019-06-21 03:35:23 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
#include <qpdf/PointerHolder.hh>
|
|
|
|
#include <qpdf/QIntC.hh>
|
2019-06-13 13:28:38 +00:00
|
|
|
#include <iostream>
|
2019-06-21 03:35:23 +00:00
|
|
|
#include <string>
|
2019-06-13 13:28:38 +00:00
|
|
|
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size);
|
|
|
|
|
2019-06-21 03:35:23 +00:00
|
|
|
static void read_file_into_memory(
|
|
|
|
char const* filename,
|
|
|
|
PointerHolder<unsigned char>& file_buf, size_t& size)
|
|
|
|
{
|
|
|
|
FILE* f = QUtil::safe_fopen(filename, "rb");
|
|
|
|
fseek(f, 0, SEEK_END);
|
|
|
|
size = QIntC::to_size(QUtil::tell(f));
|
|
|
|
fseek(f, 0, SEEK_SET);
|
|
|
|
file_buf = PointerHolder<unsigned char>(true, new unsigned char[size]);
|
|
|
|
unsigned char* buf_p = file_buf.getPointer();
|
|
|
|
size_t bytes_read = 0;
|
|
|
|
size_t len = 0;
|
|
|
|
while ((len = fread(buf_p + bytes_read, 1, size - bytes_read, f)) > 0)
|
|
|
|
{
|
|
|
|
bytes_read += len;
|
|
|
|
}
|
|
|
|
if (bytes_read != size)
|
|
|
|
{
|
|
|
|
throw std::runtime_error(
|
|
|
|
std::string("failure reading file ") + filename +
|
|
|
|
" into memory: read " +
|
|
|
|
QUtil::uint_to_string(bytes_read) + "; wanted " +
|
|
|
|
QUtil::uint_to_string(size));
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
2019-06-13 13:28:38 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
for (int i = 1; i < argc; i++)
|
|
|
|
{
|
2019-06-21 03:35:23 +00:00
|
|
|
PointerHolder<unsigned char> file_buf;
|
|
|
|
size_t size = 0;
|
|
|
|
read_file_into_memory(argv[i], file_buf, size);
|
|
|
|
LLVMFuzzerTestOneInput(file_buf.getPointer(), size);
|
2019-06-14 16:34:23 +00:00
|
|
|
std::cout << argv[i] << " successful" << std::endl;
|
2019-06-13 13:28:38 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|