summaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-03-06 17:25:09 +0100
committerJay Berkenbilt <ejb@ql.org>2018-03-06 17:34:07 +0100
commite4e2e26d990d038b0d35e7466c8a24dbfafab7d2 (patch)
tree3f9341102bdadb710912b700e26b8be6e2288123 /libqpdf
parent1a4dcb4aaf987631caa93a9d3a5b42ca439bb6ae (diff)
downloadqpdf-e4e2e26d990d038b0d35e7466c8a24dbfafab7d2.tar.zst
Properly handle pages with no contents (fixes #194)
Remove calls to assertPageObject(). All cases in the library that called assertPageObject() work fine if you don't call assertPageObject() because nothing assumes anything that was being checked by that call. Removing the calls enables more files to be successfully processed.
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFObjectHandle.cc32
-rw-r--r--libqpdf/QPDF_pages.cc2
2 files changed, 23 insertions, 11 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index 2e9cc996..c178a492 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -932,8 +932,6 @@ QPDFObjectHandle::getGeneration() const
std::map<std::string, QPDFObjectHandle>
QPDFObjectHandle::getPageImages()
{
- assertPageObject();
-
// Note: this code doesn't handle inherited resources. If this
// page dictionary doesn't have a /Resources key or has one whose
// value is null or an empty dictionary, you are supposed to walk
@@ -1081,7 +1079,6 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first)
void
QPDFObjectHandle::rotatePage(int angle, bool relative)
{
- assertPageObject();
if ((angle % 90) != 0)
{
throw std::runtime_error(
@@ -1137,7 +1134,6 @@ QPDFObjectHandle::rotatePage(int angle, bool relative)
void
QPDFObjectHandle::coalesceContentStreams()
{
- assertPageObject();
QPDFObjectHandle contents = this->getKey("/Contents");
if (contents.isStream())
{
@@ -1218,7 +1214,6 @@ QPDFObjectHandle::parse(std::string const& object_str,
void
QPDFObjectHandle::pipePageContents(Pipeline* p)
{
- assertPageObject();
std::string description = "page object " +
QUtil::int_to_string(this->m->objid) + " " +
QUtil::int_to_string(this->m->generation);
@@ -1256,7 +1251,6 @@ QPDFObjectHandle::pipeContentStreams(
void
QPDFObjectHandle::parsePageContents(ParserCallbacks* callbacks)
{
- assertPageObject();
std::string description = "page object " +
QUtil::int_to_string(this->m->objid) + " " +
QUtil::int_to_string(this->m->generation);
@@ -1267,7 +1261,6 @@ QPDFObjectHandle::parsePageContents(ParserCallbacks* callbacks)
void
QPDFObjectHandle::filterPageContents(TokenFilter* filter, Pipeline* next)
{
- assertPageObject();
std::string description = "token filter for page object " +
QUtil::int_to_string(this->m->objid) + " " +
QUtil::int_to_string(this->m->generation);
@@ -2222,8 +2215,29 @@ QPDFObjectHandle::assertNumber()
bool
QPDFObjectHandle::isPageObject()
{
- // Some PDF files have /Type broken on pages.
- return (this->isDictionary() && this->hasKey("/Contents"));
+ // See comments in QPDFObjectHandle.hh.
+ if (! this->isDictionary())
+ {
+ return false;
+ }
+ if (this->hasKey("/Type"))
+ {
+ QPDFObjectHandle type = this->getKey("/Type");
+ if (type.isName() && (type.getName() == "/Page"))
+ {
+ return true;
+ }
+ // Files have been seen in the wild that have /Type (Page)
+ if (type.isString() && (type.getStringValue() == "Page"))
+ {
+ return true;
+ }
+ }
+ if (this->hasKey("/Contents"))
+ {
+ return true;
+ }
+ return false;
}
bool
diff --git a/libqpdf/QPDF_pages.cc b/libqpdf/QPDF_pages.cc
index 31307e4e..ea5afdb5 100644
--- a/libqpdf/QPDF_pages.cc
+++ b/libqpdf/QPDF_pages.cc
@@ -191,7 +191,6 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
// pos = npages adds to the end.
flattenPagesTree();
- newpage.assertPageObject();
if (! newpage.isIndirect())
{
@@ -288,7 +287,6 @@ QPDF::addPage(QPDFObjectHandle newpage, bool first)
int
QPDF::findPage(QPDFObjectHandle& page)
{
- page.assertPageObject();
return findPage(page.getObjGen());
}