Commit 5c6cc0e63041f719be953fa8b14bf0e5038f12de

Authored by m-holger
Committed by GitHub
2 parents c8862b5f 1b89f665

Merge pull request #1492 from m-holger/fuzz

Add `info` logging for page processing in `qpdf_page_fuzzer`
Showing 1 changed file with 28 additions and 2 deletions
fuzz/qpdf_page_fuzzer.cc
@@ -12,8 +12,10 @@ @@ -12,8 +12,10 @@
12 #include <qpdf/QPDFPageDocumentHelper.hh> 12 #include <qpdf/QPDFPageDocumentHelper.hh>
13 #include <qpdf/QPDFPageLabelDocumentHelper.hh> 13 #include <qpdf/QPDFPageLabelDocumentHelper.hh>
14 #include <qpdf/QPDFPageObjectHelper.hh> 14 #include <qpdf/QPDFPageObjectHelper.hh>
15 -#include <qpdf/QUtil.hh> 15 +
  16 +#include <chrono>
16 #include <cstdlib> 17 #include <cstdlib>
  18 +#include <iostream>
17 19
18 class DiscardContents: public QPDFObjectHandle::ParserCallbacks 20 class DiscardContents: public QPDFObjectHandle::ParserCallbacks
19 { 21 {
@@ -40,13 +42,27 @@ class FuzzHelper @@ -40,13 +42,27 @@ class FuzzHelper
40 void testPages(); 42 void testPages();
41 void doChecks(); 43 void doChecks();
42 44
  45 + void
  46 + info(std::string const& msg, int pageno = 0) const
  47 + {
  48 + const std::chrono::duration<double> elapsed{std::chrono::steady_clock::now() - start};
  49 +
  50 + std::cerr << elapsed.count() << " info - " << msg;
  51 + if (pageno > 0) {
  52 + std::cerr << " page " << pageno;
  53 + }
  54 + std::cerr << '\n';
  55 + }
  56 +
43 Buffer input_buffer; 57 Buffer input_buffer;
44 Pl_Discard discard; 58 Pl_Discard discard;
  59 + const std::chrono::time_point<std::chrono::steady_clock> start;
45 }; 60 };
46 61
47 FuzzHelper::FuzzHelper(unsigned char const* data, size_t size) : 62 FuzzHelper::FuzzHelper(unsigned char const* data, size_t size) :
48 // We do not modify data, so it is safe to remove the const for Buffer 63 // We do not modify data, so it is safe to remove the const for Buffer
49 - input_buffer(const_cast<unsigned char*>(data), size) 64 + input_buffer(const_cast<unsigned char*>(data), size),
  65 + start(std::chrono::steady_clock::now())
50 { 66 {
51 } 67 }
52 68
@@ -67,24 +83,34 @@ FuzzHelper::testPages() @@ -67,24 +83,34 @@ FuzzHelper::testPages()
67 // Parse all content streams, and exercise some helpers that 83 // Parse all content streams, and exercise some helpers that
68 // operate on pages. 84 // operate on pages.
69 std::shared_ptr<QPDF> q = getQpdf(); 85 std::shared_ptr<QPDF> q = getQpdf();
  86 + info("getQpdf done");
70 QPDFPageDocumentHelper pdh(*q); 87 QPDFPageDocumentHelper pdh(*q);
71 QPDFPageLabelDocumentHelper pldh(*q); 88 QPDFPageLabelDocumentHelper pldh(*q);
72 QPDFOutlineDocumentHelper odh(*q); 89 QPDFOutlineDocumentHelper odh(*q);
73 QPDFAcroFormDocumentHelper afdh(*q); 90 QPDFAcroFormDocumentHelper afdh(*q);
74 afdh.generateAppearancesIfNeeded(); 91 afdh.generateAppearancesIfNeeded();
  92 + info("generateAppearancesIfNeeded done");
75 pdh.flattenAnnotations(); 93 pdh.flattenAnnotations();
  94 + info("flattenAnnotations done");
76 DiscardContents discard_contents; 95 DiscardContents discard_contents;
77 int pageno = 0; 96 int pageno = 0;
78 for (auto& page: pdh.getAllPages()) { 97 for (auto& page: pdh.getAllPages()) {
79 ++pageno; 98 ++pageno;
80 try { 99 try {
  100 + info("start page", pageno);
81 page.coalesceContentStreams(); 101 page.coalesceContentStreams();
  102 + info("coalesceContentStreams done");
82 page.parseContents(&discard_contents); 103 page.parseContents(&discard_contents);
  104 + info("parseContents done");
83 page.getImages(); 105 page.getImages();
  106 + info("getImages done");
84 pldh.getLabelForPage(pageno); 107 pldh.getLabelForPage(pageno);
  108 + info("getLabelForPage done");
85 QPDFObjectHandle page_obj(page.getObjectHandle()); 109 QPDFObjectHandle page_obj(page.getObjectHandle());
86 page_obj.getJSON(JSON::LATEST, true).unparse(); 110 page_obj.getJSON(JSON::LATEST, true).unparse();
  111 + info("getJSON done");
87 odh.getOutlinesForPage(page_obj); 112 odh.getOutlinesForPage(page_obj);
  113 + info("getOutlinesForPage done");
88 114
89 for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) { 115 for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) {
90 afdh.getFieldForAnnotation(aoh); 116 afdh.getFieldForAnnotation(aoh);