aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--qpdf/qtest/qpdf/split-tokens-split.out3
6 files changed, 21 insertions, 31 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
diff --git a/qpdf/qtest/qpdf/split-tokens-split.out b/qpdf/qtest/qpdf/split-tokens-split.out
index 8e1003be..828abb5b 100644
--- a/qpdf/qtest/qpdf/split-tokens-split.out
+++ b/qpdf/qtest/qpdf/split-tokens-split.out
@@ -1,5 +1,4 @@
-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
-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
+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
WARNING: empty PDF: content normalization encountered bad tokens
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
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.