diff --git a/ChangeLog b/ChangeLog index 8816d6cf..77ab74b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2014-11-14 Jay Berkenbilt + + * 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 * 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 Binary files /dev/null and b/qpdf/qtest/qpdf/page-no-content.pdf differ