Commit c47e332dbfdd35b0c52cf41a122fa9cea348736f
1 parent
58ed11f2
Allow null `callbacks` in content stream handling
Introduce null checks for `callbacks` in `QPDFObjectHandle` to allow content streams to be parsed without ParserCallbacks. Update `QPDFJob` to pass `nullptr` instead of `DiscardContents` for parsing.
Showing
8 changed files
with
17 additions
and
110 deletions
fuzz/qpdf_crypt_fuzzer.cc
| ... | ... | @@ -13,20 +13,6 @@ |
| 13 | 13 | |
| 14 | 14 | #include <cstdlib> |
| 15 | 15 | |
| 16 | -class DiscardContents: public QPDFObjectHandle::ParserCallbacks | |
| 17 | -{ | |
| 18 | - public: | |
| 19 | - ~DiscardContents() override = default; | |
| 20 | - void | |
| 21 | - handleObject(QPDFObjectHandle) override | |
| 22 | - { | |
| 23 | - } | |
| 24 | - void | |
| 25 | - handleEOF() override | |
| 26 | - { | |
| 27 | - } | |
| 28 | -}; | |
| 29 | - | |
| 30 | 16 | class FuzzHelper |
| 31 | 17 | { |
| 32 | 18 | public: | ... | ... |
fuzz/qpdf_crypt_insecure_fuzzer.cc
| ... | ... | @@ -12,20 +12,6 @@ |
| 12 | 12 | #include <qpdf/QUtil.hh> |
| 13 | 13 | #include <cstdlib> |
| 14 | 14 | |
| 15 | -class DiscardContents: public QPDFObjectHandle::ParserCallbacks | |
| 16 | -{ | |
| 17 | - public: | |
| 18 | - ~DiscardContents() override = default; | |
| 19 | - void | |
| 20 | - handleObject(QPDFObjectHandle) override | |
| 21 | - { | |
| 22 | - } | |
| 23 | - void | |
| 24 | - handleEOF() override | |
| 25 | - { | |
| 26 | - } | |
| 27 | -}; | |
| 28 | - | |
| 29 | 15 | class FuzzHelper |
| 30 | 16 | { |
| 31 | 17 | public: | ... | ... |
fuzz/qpdf_fuzzer.cc
| ... | ... | @@ -12,20 +12,6 @@ |
| 12 | 12 | #include <qpdf/QUtil.hh> |
| 13 | 13 | #include <cstdlib> |
| 14 | 14 | |
| 15 | -class DiscardContents: public QPDFObjectHandle::ParserCallbacks | |
| 16 | -{ | |
| 17 | - public: | |
| 18 | - ~DiscardContents() override = default; | |
| 19 | - void | |
| 20 | - handleObject(QPDFObjectHandle) override | |
| 21 | - { | |
| 22 | - } | |
| 23 | - void | |
| 24 | - handleEOF() override | |
| 25 | - { | |
| 26 | - } | |
| 27 | -}; | |
| 28 | - | |
| 29 | 15 | class FuzzHelper |
| 30 | 16 | { |
| 31 | 17 | public: | ... | ... |
fuzz/qpdf_lin_fuzzer.cc
| ... | ... | @@ -12,20 +12,6 @@ |
| 12 | 12 | #include <qpdf/QUtil.hh> |
| 13 | 13 | #include <cstdlib> |
| 14 | 14 | |
| 15 | -class DiscardContents: public QPDFObjectHandle::ParserCallbacks | |
| 16 | -{ | |
| 17 | - public: | |
| 18 | - ~DiscardContents() override = default; | |
| 19 | - void | |
| 20 | - handleObject(QPDFObjectHandle) override | |
| 21 | - { | |
| 22 | - } | |
| 23 | - void | |
| 24 | - handleEOF() override | |
| 25 | - { | |
| 26 | - } | |
| 27 | -}; | |
| 28 | - | |
| 29 | 15 | class FuzzHelper |
| 30 | 16 | { |
| 31 | 17 | public: | ... | ... |
fuzz/qpdf_outlines_fuzzer.cc
| ... | ... | @@ -12,20 +12,6 @@ |
| 12 | 12 | #include <qpdf/QUtil.hh> |
| 13 | 13 | #include <cstdlib> |
| 14 | 14 | |
| 15 | -class DiscardContents: public QPDFObjectHandle::ParserCallbacks | |
| 16 | -{ | |
| 17 | - public: | |
| 18 | - ~DiscardContents() override = default; | |
| 19 | - void | |
| 20 | - handleObject(QPDFObjectHandle) override | |
| 21 | - { | |
| 22 | - } | |
| 23 | - void | |
| 24 | - handleEOF() override | |
| 25 | - { | |
| 26 | - } | |
| 27 | -}; | |
| 28 | - | |
| 29 | 15 | class FuzzHelper |
| 30 | 16 | { |
| 31 | 17 | public: | ... | ... |
fuzz/qpdf_page_fuzzer.cc
| ... | ... | @@ -17,20 +17,6 @@ |
| 17 | 17 | #include <cstdlib> |
| 18 | 18 | #include <iostream> |
| 19 | 19 | |
| 20 | -class DiscardContents: public QPDFObjectHandle::ParserCallbacks | |
| 21 | -{ | |
| 22 | - public: | |
| 23 | - ~DiscardContents() override = default; | |
| 24 | - void | |
| 25 | - handleObject(QPDFObjectHandle) override | |
| 26 | - { | |
| 27 | - } | |
| 28 | - void | |
| 29 | - handleEOF() override | |
| 30 | - { | |
| 31 | - } | |
| 32 | -}; | |
| 33 | - | |
| 34 | 20 | class FuzzHelper |
| 35 | 21 | { |
| 36 | 22 | public: |
| ... | ... | @@ -92,7 +78,6 @@ FuzzHelper::testPages() |
| 92 | 78 | info("generateAppearancesIfNeeded done"); |
| 93 | 79 | pdh.flattenAnnotations(); |
| 94 | 80 | info("flattenAnnotations done"); |
| 95 | - DiscardContents discard_contents; | |
| 96 | 81 | int pageno = 0; |
| 97 | 82 | for (auto& page: pdh.getAllPages()) { |
| 98 | 83 | ++pageno; |
| ... | ... | @@ -100,7 +85,7 @@ FuzzHelper::testPages() |
| 100 | 85 | info("start page", pageno); |
| 101 | 86 | page.coalesceContentStreams(); |
| 102 | 87 | info("coalesceContentStreams done"); |
| 103 | - page.parseContents(&discard_contents); | |
| 88 | + page.parseContents(nullptr); | |
| 104 | 89 | info("parseContents done"); |
| 105 | 90 | page.getImages(); |
| 106 | 91 | info("getImages done"); | ... | ... |
libqpdf/QPDFJob.cc
| ... | ... | @@ -62,20 +62,6 @@ namespace |
| 62 | 62 | std::shared_ptr<Pl_DCT::CompressConfig> config; |
| 63 | 63 | }; |
| 64 | 64 | |
| 65 | - class DiscardContents: public QPDFObjectHandle::ParserCallbacks | |
| 66 | - { | |
| 67 | - public: | |
| 68 | - ~DiscardContents() override = default; | |
| 69 | - void | |
| 70 | - handleObject(QPDFObjectHandle) override | |
| 71 | - { | |
| 72 | - } | |
| 73 | - void | |
| 74 | - handleEOF() override | |
| 75 | - { | |
| 76 | - } | |
| 77 | - }; | |
| 78 | - | |
| 79 | 65 | struct QPDFPageData |
| 80 | 66 | { |
| 81 | 67 | QPDFPageData(std::string const& filename, QPDF* qpdf, std::string const& range); |
| ... | ... | @@ -810,12 +796,11 @@ QPDFJob::doCheck(QPDF& pdf) |
| 810 | 796 | w.write(); |
| 811 | 797 | |
| 812 | 798 | // Parse all content streams |
| 813 | - DiscardContents discard_contents; | |
| 814 | 799 | int pageno = 0; |
| 815 | 800 | for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 816 | 801 | ++pageno; |
| 817 | 802 | try { |
| 818 | - page.parseContents(&discard_contents); | |
| 803 | + page.parseContents(nullptr); | |
| 819 | 804 | } catch (QPDFExc& e) { |
| 820 | 805 | okay = false; |
| 821 | 806 | *m->log->getError() << "ERROR: page " << pageno << ": " << e.what() << "\n"; | ... | ... |
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -1549,13 +1549,17 @@ QPDFObjectHandle::parseContentStream_internal( |
| 1549 | 1549 | pl::String buf(stream_data); |
| 1550 | 1550 | std::string all_description; |
| 1551 | 1551 | pipeContentStreams(&buf, description, all_description); |
| 1552 | - callbacks->contentSize(stream_data.size()); | |
| 1552 | + if (callbacks) { | |
| 1553 | + callbacks->contentSize(stream_data.size()); | |
| 1554 | + } | |
| 1553 | 1555 | try { |
| 1554 | 1556 | parseContentStream_data(stream_data, all_description, callbacks, getOwningQPDF()); |
| 1555 | 1557 | } catch (TerminateParsing&) { |
| 1556 | 1558 | return; |
| 1557 | 1559 | } |
| 1558 | - callbacks->handleEOF(); | |
| 1560 | + if (callbacks) { | |
| 1561 | + callbacks->handleEOF(); | |
| 1562 | + } | |
| 1559 | 1563 | } |
| 1560 | 1564 | |
| 1561 | 1565 | void |
| ... | ... | @@ -1583,8 +1587,9 @@ QPDFObjectHandle::parseContentStream_data( |
| 1583 | 1587 | break; |
| 1584 | 1588 | } |
| 1585 | 1589 | size_t length = QIntC::to_size(input.tell() - offset); |
| 1586 | - | |
| 1587 | - callbacks->handleObject(obj, QIntC::to_size(offset), length); | |
| 1590 | + if (callbacks) { | |
| 1591 | + callbacks->handleObject(obj, QIntC::to_size(offset), length); | |
| 1592 | + } | |
| 1588 | 1593 | if (obj.isOperator() && (obj.getOperatorValue() == "ID")) { |
| 1589 | 1594 | // Discard next character; it is the space after ID that terminated the token. Read |
| 1590 | 1595 | // until end of inline image. |
| ... | ... | @@ -1606,10 +1611,12 @@ QPDFObjectHandle::parseContentStream_data( |
| 1606 | 1611 | "EOF found while reading inline image")); |
| 1607 | 1612 | } else { |
| 1608 | 1613 | QTC::TC("qpdf", "QPDFObjectHandle inline image token"); |
| 1609 | - callbacks->handleObject( | |
| 1610 | - QPDFObjectHandle::newInlineImage(tokenizer.getValue()), | |
| 1611 | - QIntC::to_size(offset), | |
| 1612 | - length); | |
| 1614 | + if (callbacks) { | |
| 1615 | + callbacks->handleObject( | |
| 1616 | + QPDFObjectHandle::newInlineImage(tokenizer.getValue()), | |
| 1617 | + QIntC::to_size(offset), | |
| 1618 | + length); | |
| 1619 | + } | |
| 1613 | 1620 | } |
| 1614 | 1621 | } |
| 1615 | 1622 | } | ... | ... |