aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-03-04 21:47:51 +0100
committerJay Berkenbilt <ejb@ql.org>2021-03-04 21:59:45 +0100
commitf68e25c7f278bbfee095d43d4405a74df0bd22ff (patch)
tree6d6b18378c8438b927aa88264ba7ab3c02a7c758 /libqpdf
parentaa89476e155a25c4f44dc375885395a2734a547f (diff)
downloadqpdf-f68e25c7f278bbfee095d43d4405a74df0bd22ff.tar.zst
Don't use handleWarning, which is being reverted
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFAcroFormDocumentHelper.cc6
-rw-r--r--libqpdf/QPDFObjectHandle.cc7
-rw-r--r--libqpdf/QPDFPageObjectHelper.cc20
-rw-r--r--libqpdf/ResourceFinder.cc12
-rw-r--r--libqpdf/qpdf/ResourceFinder.hh4
5 files changed, 20 insertions, 29 deletions
diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc
index 7491d5a7..b0777f9b 100644
--- a/libqpdf/QPDFAcroFormDocumentHelper.cc
+++ b/libqpdf/QPDFAcroFormDocumentHelper.cc
@@ -742,8 +742,9 @@ QPDFAcroFormDocumentHelper::adjustDefaultAppearances(
&this->qpdf, DA.getUTF8Value());
try
{
+ auto nwarnings = this->qpdf.numWarnings();
da_stream.parseAsContents(&rf);
- if (rf.sawBad())
+ if (this->qpdf.numWarnings() > nwarnings)
{
QTC::TC("qpdf", "QPDFAcroFormDocumentHelper /DA parse error");
}
@@ -858,8 +859,9 @@ QPDFAcroFormDocumentHelper::adjustAppearanceStream(
ResourceFinder rf;
try
{
+ auto nwarnings = this->qpdf.numWarnings();
stream.parseAsContents(&rf);
- if (rf.sawBad())
+ if (this->qpdf.numWarnings() > nwarnings)
{
QTC::TC("qpdf", "QPDFAcroFormDocumentHelper AP parse error");
}
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index 221ecd1d..e7d84b4c 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -1949,15 +1949,10 @@ QPDFObjectHandle::parseContentStream_internal(
pipeContentStreams(&buf, description, all_description);
PointerHolder<Buffer> stream_data = buf.getBuffer();
callbacks->contentSize(stream_data->getSize());
- QPDF* context = getOwningQPDF();
- if ((! context) && isArray() && (getArrayNItems() > 0))
- {
- context = getArrayItem(0).getOwningQPDF();
- }
try
{
parseContentStream_data(stream_data, all_description,
- callbacks, context);
+ callbacks, getOwningQPDF());
}
catch (TerminateParsing&)
{
diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc
index 43c4eef6..7f7e6bea 100644
--- a/libqpdf/QPDFPageObjectHelper.cc
+++ b/libqpdf/QPDFPageObjectHelper.cc
@@ -684,24 +684,28 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper(
ResourceFinder rf;
try
{
+ auto q = ph.oh.getOwningQPDF();
+ size_t before_nw = (q ? q->numWarnings() : 0);
ph.parseContents(&rf);
+ size_t after_nw = (q ? q->numWarnings() : 0);
+ if (after_nw > before_nw)
+ {
+ ph.oh.warnIfPossible(
+ "Bad token found while scanning content stream; "
+ "not attempting to remove unreferenced objects from"
+ " this object");
+ return false;
+ }
}
catch (std::exception& e)
{
+ QTC::TC("qpdf", "QPDFPageObjectHelper bad token finding names");
ph.oh.warnIfPossible(
std::string("Unable to parse content stream: ") + e.what() +
"; not attempting to remove unreferenced objects"
" from this object");
return false;
}
- if (rf.sawBad())
- {
- QTC::TC("qpdf", "QPDFPageObjectHelper bad token finding names");
- ph.oh.warnIfPossible(
- "Bad token found while scanning content stream; "
- "not attempting to remove unreferenced objects from this object");
- return false;
- }
// We will walk through /Font and /XObject dictionaries, removing
// any resources that are not referenced. We must make copies of
diff --git a/libqpdf/ResourceFinder.cc b/libqpdf/ResourceFinder.cc
index 6b9929e4..8d430be5 100644
--- a/libqpdf/ResourceFinder.cc
+++ b/libqpdf/ResourceFinder.cc
@@ -1,8 +1,7 @@
#include <qpdf/ResourceFinder.hh>
ResourceFinder::ResourceFinder() :
- last_name_offset(0),
- saw_bad(false)
+ last_name_offset(0)
{
}
@@ -45,9 +44,8 @@ ResourceFinder::handleObject(QPDFObjectHandle obj, size_t offset, size_t)
}
void
-ResourceFinder::handleWarning()
+ResourceFinder::handleEOF()
{
- this->saw_bad = true;
}
std::set<std::string> const&
@@ -61,9 +59,3 @@ ResourceFinder::getNamesByResourceType() const
{
return this->names_by_resource_type;
}
-
-bool
-ResourceFinder::sawBad() const
-{
- return this->saw_bad;
-}
diff --git a/libqpdf/qpdf/ResourceFinder.hh b/libqpdf/qpdf/ResourceFinder.hh
index ac3d5b4c..8d3c6782 100644
--- a/libqpdf/qpdf/ResourceFinder.hh
+++ b/libqpdf/qpdf/ResourceFinder.hh
@@ -9,12 +9,11 @@ class ResourceFinder: public QPDFObjectHandle::ParserCallbacks
ResourceFinder();
virtual ~ResourceFinder() = default;
virtual void handleObject(QPDFObjectHandle, size_t, size_t) override;
- virtual void handleWarning() override;
+ virtual void handleEOF() override;
std::set<std::string> const& getNames() const;
std::map<std::string,
std::map<std::string,
std::set<size_t>>> const& getNamesByResourceType() const;
- bool sawBad() const;
private:
std::string last_name;
@@ -23,7 +22,6 @@ class ResourceFinder: public QPDFObjectHandle::ParserCallbacks
std::map<std::string,
std::map<std::string,
std::set<size_t>>> names_by_resource_type;
- bool saw_bad;
};
#endif // RESOURCEFINDER_HH