2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +00:00

Update qpdf_fuzzer to increase coverage

This commit is contained in:
Jay Berkenbilt 2019-06-21 17:39:19 -04:00
parent b07ad6794e
commit 793d987b5f

View File

@ -58,9 +58,7 @@ FuzzHelper::getWriter(PointerHolder<QPDF> qpdf)
{
PointerHolder<QPDFWriter> w = new QPDFWriter(*qpdf);
w->setOutputPipeline(&this->discard);
w->setDeterministicID(true);
w->setDecodeLevel(qpdf_dl_all);
w->setCompressStreams(false);
return w;
}
@ -75,6 +73,10 @@ FuzzHelper::doWrite(PointerHolder<QPDFWriter> w)
{
std::cerr << e.what() << std::endl;
}
catch (std::runtime_error const& e)
{
std::cerr << e.what() << std::endl;
}
}
void
@ -87,21 +89,31 @@ FuzzHelper::testWrite()
q = getQpdf();
w = getWriter(q);
w->setDeterministicID(true);
w->setQDFMode(true);
doWrite(w);
q = getQpdf();
w = getWriter(q);
w->setStaticID(true);
w->setLinearization(true);
w->setR6EncryptionParameters(
"u", "o", true, true, true, true, true, true, qpdf_r3p_full, true);
doWrite(w);
q = getQpdf();
w = getWriter(q);
w->setStaticID(true);
w->setObjectStreamMode(qpdf_o_disable);
w->setR3EncryptionParameters(
"u", "o", true, true, qpdf_r3p_full, qpdf_r3m_all);
doWrite(w);
q = getQpdf();
w = getWriter(q);
w->setDeterministicID(true);
w->setObjectStreamMode(qpdf_o_generate);
w->setLinearization(true);
doWrite(w);
}
@ -115,6 +127,8 @@ FuzzHelper::testPages()
QPDFPageLabelDocumentHelper pldh(*q);
QPDFOutlineDocumentHelper odh(*q);
QPDFAcroFormDocumentHelper afdh(*q);
afdh.generateAppearancesIfNeeded();
pdh.flattenAnnotations();
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
DiscardContents discard_contents;
int pageno = 0;
@ -126,10 +140,13 @@ FuzzHelper::testPages()
++pageno;
try
{
page.coalesceContentStreams();
page.parsePageContents(&discard_contents);
page.getPageImages();
pldh.getLabelForPage(pageno);
odh.getOutlinesForPage(page.getObjectHandle().getObjGen());
QPDFObjectHandle page_obj(page.getObjectHandle());
page_obj.getJSON(true).unparse();
odh.getOutlinesForPage(page_obj.getObjGen());
std::vector<QPDFAnnotationObjectHelper> annotations =
afdh.getWidgetAnnotationsForPage(page);