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 12 #include <qpdf/QPDFPageDocumentHelper.hh>
13 13 #include <qpdf/QPDFPageLabelDocumentHelper.hh>
14 14 #include <qpdf/QPDFPageObjectHelper.hh>
15   -#include <qpdf/QUtil.hh>
  15 +
  16 +#include <chrono>
16 17 #include <cstdlib>
  18 +#include <iostream>
17 19  
18 20 class DiscardContents: public QPDFObjectHandle::ParserCallbacks
19 21 {
... ... @@ -40,13 +42,27 @@ class FuzzHelper
40 42 void testPages();
41 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 57 Buffer input_buffer;
44 58 Pl_Discard discard;
  59 + const std::chrono::time_point<std::chrono::steady_clock> start;
45 60 };
46 61  
47 62 FuzzHelper::FuzzHelper(unsigned char const* data, size_t size) :
48 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 83 // Parse all content streams, and exercise some helpers that
68 84 // operate on pages.
69 85 std::shared_ptr<QPDF> q = getQpdf();
  86 + info("getQpdf done");
70 87 QPDFPageDocumentHelper pdh(*q);
71 88 QPDFPageLabelDocumentHelper pldh(*q);
72 89 QPDFOutlineDocumentHelper odh(*q);
73 90 QPDFAcroFormDocumentHelper afdh(*q);
74 91 afdh.generateAppearancesIfNeeded();
  92 + info("generateAppearancesIfNeeded done");
75 93 pdh.flattenAnnotations();
  94 + info("flattenAnnotations done");
76 95 DiscardContents discard_contents;
77 96 int pageno = 0;
78 97 for (auto& page: pdh.getAllPages()) {
79 98 ++pageno;
80 99 try {
  100 + info("start page", pageno);
81 101 page.coalesceContentStreams();
  102 + info("coalesceContentStreams done");
82 103 page.parseContents(&discard_contents);
  104 + info("parseContents done");
83 105 page.getImages();
  106 + info("getImages done");
84 107 pldh.getLabelForPage(pageno);
  108 + info("getLabelForPage done");
85 109 QPDFObjectHandle page_obj(page.getObjectHandle());
86 110 page_obj.getJSON(JSON::LATEST, true).unparse();
  111 + info("getJSON done");
87 112 odh.getOutlinesForPage(page_obj);
  113 + info("getOutlinesForPage done");
88 114  
89 115 for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) {
90 116 afdh.getFieldForAnnotation(aoh);
... ...