aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2014-11-14 19:43:34 +0100
committerJay Berkenbilt <ejb@ql.org>2014-11-14 19:43:34 +0100
commitcaab1b0e1642bc6ee0194c7ab4c4a4de2ab22f2c (patch)
tree289badc34732a92059a939935a67f37fbbb8b8b2
parent4071db59aa475b42ba4db71462ab4f83b4bd2132 (diff)
downloadqpdf-caab1b0e1642bc6ee0194c7ab4c4a4de2ab22f2c.tar.zst
Handle pages with no /Contents from getPageContents()
The spec allows /Contents to be omitted for pages that are blank, but QPDFObjectHandle::getPageContents() was throwing an exception in this case.
-rw-r--r--ChangeLog8
-rw-r--r--libqpdf/QPDFObjectHandle.cc2
-rw-r--r--qpdf/qtest/qpdf.test7
-rw-r--r--qpdf/qtest/qpdf/page-no-content.out8
-rw-r--r--qpdf/qtest/qpdf/page-no-content.pdfbin0 -> 1362 bytes
5 files changed, 23 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 8816d6cf..77ab74b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2014-11-14 Jay Berkenbilt <ejb@ql.org>
+
+ * Bug fix: QPDFObjectHandle::getPageContents() no longer throws an
+ exception when called on a page that has no /Contents key in its
+ dictionary. This is allowed by the spec, and some software
+ packages generate files like this for pages that are blank in the
+ original.
+
2014-06-07 Jay Berkenbilt <ejb@ql.org>
* 5.1.2: release
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index ef92e3ac..eec4fae3 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -633,7 +633,7 @@ QPDFObjectHandle::getPageContents()
{
result.push_back(contents);
}
- else
+ else if (! contents.isNull())
{
throw std::runtime_error("unknown object type inspecting /Contents "
"key in page dictionary");
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index 8e697844..b2bf06a7 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -199,7 +199,7 @@ $td->runtest("remove page we don't have",
show_ntests();
# ----------
$td->notify("--- Miscellaneous Tests ---");
-$n_tests += 72;
+$n_tests += 73;
$td->runtest("qpdf version",
{$td->COMMAND => "qpdf --version"},
@@ -554,6 +554,11 @@ $td->runtest("check file",
{$td->FILE => "a.pdf"},
{$td->FILE => "indirect-decode-parms-out.pdf"});
+$td->runtest("handle page no with contents",
+ {$td->COMMAND => "qpdf --show-pages page-no-content.pdf"},
+ {$td->FILE => "page-no-content.out", $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+
show_ntests();
# ----------
$td->notify("--- Numeric range parsing tests ---");
diff --git a/qpdf/qtest/qpdf/page-no-content.out b/qpdf/qtest/qpdf/page-no-content.out
new file mode 100644
index 00000000..15df72db
--- /dev/null
+++ b/qpdf/qtest/qpdf/page-no-content.out
@@ -0,0 +1,8 @@
+page 1: 3 0 R
+ content:
+ 6 0 R
+page 2: 4 0 R
+ content:
+page 3: 5 0 R
+ content:
+ 9 0 R
diff --git a/qpdf/qtest/qpdf/page-no-content.pdf b/qpdf/qtest/qpdf/page-no-content.pdf
new file mode 100644
index 00000000..77b7832a
--- /dev/null
+++ b/qpdf/qtest/qpdf/page-no-content.pdf
Binary files differ