Commit f68e25c7f278bbfee095d43d4405a74df0bd22ff
1 parent
aa89476e
Don't use handleWarning, which is being reverted
Showing
6 changed files
with
21 additions
and
31 deletions
libqpdf/QPDFAcroFormDocumentHelper.cc
| @@ -742,8 +742,9 @@ QPDFAcroFormDocumentHelper::adjustDefaultAppearances( | @@ -742,8 +742,9 @@ QPDFAcroFormDocumentHelper::adjustDefaultAppearances( | ||
| 742 | &this->qpdf, DA.getUTF8Value()); | 742 | &this->qpdf, DA.getUTF8Value()); |
| 743 | try | 743 | try |
| 744 | { | 744 | { |
| 745 | + auto nwarnings = this->qpdf.numWarnings(); | ||
| 745 | da_stream.parseAsContents(&rf); | 746 | da_stream.parseAsContents(&rf); |
| 746 | - if (rf.sawBad()) | 747 | + if (this->qpdf.numWarnings() > nwarnings) |
| 747 | { | 748 | { |
| 748 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper /DA parse error"); | 749 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper /DA parse error"); |
| 749 | } | 750 | } |
| @@ -858,8 +859,9 @@ QPDFAcroFormDocumentHelper::adjustAppearanceStream( | @@ -858,8 +859,9 @@ QPDFAcroFormDocumentHelper::adjustAppearanceStream( | ||
| 858 | ResourceFinder rf; | 859 | ResourceFinder rf; |
| 859 | try | 860 | try |
| 860 | { | 861 | { |
| 862 | + auto nwarnings = this->qpdf.numWarnings(); | ||
| 861 | stream.parseAsContents(&rf); | 863 | stream.parseAsContents(&rf); |
| 862 | - if (rf.sawBad()) | 864 | + if (this->qpdf.numWarnings() > nwarnings) |
| 863 | { | 865 | { |
| 864 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper AP parse error"); | 866 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper AP parse error"); |
| 865 | } | 867 | } |
libqpdf/QPDFObjectHandle.cc
| @@ -1949,15 +1949,10 @@ QPDFObjectHandle::parseContentStream_internal( | @@ -1949,15 +1949,10 @@ QPDFObjectHandle::parseContentStream_internal( | ||
| 1949 | pipeContentStreams(&buf, description, all_description); | 1949 | pipeContentStreams(&buf, description, all_description); |
| 1950 | PointerHolder<Buffer> stream_data = buf.getBuffer(); | 1950 | PointerHolder<Buffer> stream_data = buf.getBuffer(); |
| 1951 | callbacks->contentSize(stream_data->getSize()); | 1951 | callbacks->contentSize(stream_data->getSize()); |
| 1952 | - QPDF* context = getOwningQPDF(); | ||
| 1953 | - if ((! context) && isArray() && (getArrayNItems() > 0)) | ||
| 1954 | - { | ||
| 1955 | - context = getArrayItem(0).getOwningQPDF(); | ||
| 1956 | - } | ||
| 1957 | try | 1952 | try |
| 1958 | { | 1953 | { |
| 1959 | parseContentStream_data(stream_data, all_description, | 1954 | parseContentStream_data(stream_data, all_description, |
| 1960 | - callbacks, context); | 1955 | + callbacks, getOwningQPDF()); |
| 1961 | } | 1956 | } |
| 1962 | catch (TerminateParsing&) | 1957 | catch (TerminateParsing&) |
| 1963 | { | 1958 | { |
libqpdf/QPDFPageObjectHelper.cc
| @@ -684,24 +684,28 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper( | @@ -684,24 +684,28 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper( | ||
| 684 | ResourceFinder rf; | 684 | ResourceFinder rf; |
| 685 | try | 685 | try |
| 686 | { | 686 | { |
| 687 | + auto q = ph.oh.getOwningQPDF(); | ||
| 688 | + size_t before_nw = (q ? q->numWarnings() : 0); | ||
| 687 | ph.parseContents(&rf); | 689 | ph.parseContents(&rf); |
| 690 | + size_t after_nw = (q ? q->numWarnings() : 0); | ||
| 691 | + if (after_nw > before_nw) | ||
| 692 | + { | ||
| 693 | + ph.oh.warnIfPossible( | ||
| 694 | + "Bad token found while scanning content stream; " | ||
| 695 | + "not attempting to remove unreferenced objects from" | ||
| 696 | + " this object"); | ||
| 697 | + return false; | ||
| 698 | + } | ||
| 688 | } | 699 | } |
| 689 | catch (std::exception& e) | 700 | catch (std::exception& e) |
| 690 | { | 701 | { |
| 702 | + QTC::TC("qpdf", "QPDFPageObjectHelper bad token finding names"); | ||
| 691 | ph.oh.warnIfPossible( | 703 | ph.oh.warnIfPossible( |
| 692 | std::string("Unable to parse content stream: ") + e.what() + | 704 | std::string("Unable to parse content stream: ") + e.what() + |
| 693 | "; not attempting to remove unreferenced objects" | 705 | "; not attempting to remove unreferenced objects" |
| 694 | " from this object"); | 706 | " from this object"); |
| 695 | return false; | 707 | return false; |
| 696 | } | 708 | } |
| 697 | - if (rf.sawBad()) | ||
| 698 | - { | ||
| 699 | - QTC::TC("qpdf", "QPDFPageObjectHelper bad token finding names"); | ||
| 700 | - ph.oh.warnIfPossible( | ||
| 701 | - "Bad token found while scanning content stream; " | ||
| 702 | - "not attempting to remove unreferenced objects from this object"); | ||
| 703 | - return false; | ||
| 704 | - } | ||
| 705 | 709 | ||
| 706 | // We will walk through /Font and /XObject dictionaries, removing | 710 | // We will walk through /Font and /XObject dictionaries, removing |
| 707 | // any resources that are not referenced. We must make copies of | 711 | // any resources that are not referenced. We must make copies of |
libqpdf/ResourceFinder.cc
| 1 | #include <qpdf/ResourceFinder.hh> | 1 | #include <qpdf/ResourceFinder.hh> |
| 2 | 2 | ||
| 3 | ResourceFinder::ResourceFinder() : | 3 | ResourceFinder::ResourceFinder() : |
| 4 | - last_name_offset(0), | ||
| 5 | - saw_bad(false) | 4 | + last_name_offset(0) |
| 6 | { | 5 | { |
| 7 | } | 6 | } |
| 8 | 7 | ||
| @@ -45,9 +44,8 @@ ResourceFinder::handleObject(QPDFObjectHandle obj, size_t offset, size_t) | @@ -45,9 +44,8 @@ ResourceFinder::handleObject(QPDFObjectHandle obj, size_t offset, size_t) | ||
| 45 | } | 44 | } |
| 46 | 45 | ||
| 47 | void | 46 | void |
| 48 | -ResourceFinder::handleWarning() | 47 | +ResourceFinder::handleEOF() |
| 49 | { | 48 | { |
| 50 | - this->saw_bad = true; | ||
| 51 | } | 49 | } |
| 52 | 50 | ||
| 53 | std::set<std::string> const& | 51 | std::set<std::string> const& |
| @@ -61,9 +59,3 @@ ResourceFinder::getNamesByResourceType() const | @@ -61,9 +59,3 @@ ResourceFinder::getNamesByResourceType() const | ||
| 61 | { | 59 | { |
| 62 | return this->names_by_resource_type; | 60 | return this->names_by_resource_type; |
| 63 | } | 61 | } |
| 64 | - | ||
| 65 | -bool | ||
| 66 | -ResourceFinder::sawBad() const | ||
| 67 | -{ | ||
| 68 | - return this->saw_bad; | ||
| 69 | -} |
libqpdf/qpdf/ResourceFinder.hh
| @@ -9,12 +9,11 @@ class ResourceFinder: public QPDFObjectHandle::ParserCallbacks | @@ -9,12 +9,11 @@ class ResourceFinder: public QPDFObjectHandle::ParserCallbacks | ||
| 9 | ResourceFinder(); | 9 | ResourceFinder(); |
| 10 | virtual ~ResourceFinder() = default; | 10 | virtual ~ResourceFinder() = default; |
| 11 | virtual void handleObject(QPDFObjectHandle, size_t, size_t) override; | 11 | virtual void handleObject(QPDFObjectHandle, size_t, size_t) override; |
| 12 | - virtual void handleWarning() override; | 12 | + virtual void handleEOF() override; |
| 13 | std::set<std::string> const& getNames() const; | 13 | std::set<std::string> const& getNames() const; |
| 14 | std::map<std::string, | 14 | std::map<std::string, |
| 15 | std::map<std::string, | 15 | std::map<std::string, |
| 16 | std::set<size_t>>> const& getNamesByResourceType() const; | 16 | std::set<size_t>>> const& getNamesByResourceType() const; |
| 17 | - bool sawBad() const; | ||
| 18 | 17 | ||
| 19 | private: | 18 | private: |
| 20 | std::string last_name; | 19 | std::string last_name; |
| @@ -23,7 +22,6 @@ class ResourceFinder: public QPDFObjectHandle::ParserCallbacks | @@ -23,7 +22,6 @@ class ResourceFinder: public QPDFObjectHandle::ParserCallbacks | ||
| 23 | std::map<std::string, | 22 | std::map<std::string, |
| 24 | std::map<std::string, | 23 | std::map<std::string, |
| 25 | std::set<size_t>>> names_by_resource_type; | 24 | std::set<size_t>>> names_by_resource_type; |
| 26 | - bool saw_bad; | ||
| 27 | }; | 25 | }; |
| 28 | 26 | ||
| 29 | #endif // RESOURCEFINDER_HH | 27 | #endif // RESOURCEFINDER_HH |
qpdf/qtest/qpdf/split-tokens-split.out
| 1 | -WARNING: page object 3 0 stream 5 0, stream 7 0, stream 9 0, stream 11 0 (content, offset 375): null character not allowed in name token | ||
| 2 | -WARNING: split-tokens.pdf, object 3 0 at offset 181: Bad token found while scanning content stream; not attempting to remove unreferenced objects from this object | 1 | +WARNING: split-tokens.pdf, object 3 0 at offset 181: Unable to parse content stream: page object 3 0 stream 5 0, stream 7 0, stream 9 0, stream 11 0 (content, offset 375): null character not allowed in name token; not attempting to remove unreferenced objects from this object |
| 3 | WARNING: empty PDF: content normalization encountered bad tokens | 2 | WARNING: empty PDF: content normalization encountered bad tokens |
| 4 | WARNING: empty PDF: normalized content ended with a bad token; you may be able to resolve this by coalescing content streams in combination with normalizing content. From the command line, specify --coalesce-contents | 3 | WARNING: empty PDF: normalized content ended with a bad token; you may be able to resolve this by coalescing content streams in combination with normalizing content. From the command line, specify --coalesce-contents |
| 5 | WARNING: empty PDF: Resulting stream data may be corrupted but is may still useful for manual inspection. For more information on this warning, search for content normalization in the manual. | 4 | WARNING: empty PDF: Resulting stream data may be corrupted but is may still useful for manual inspection. For more information on this warning, search for content normalization in the manual. |