From caab1b0e1642bc6ee0194c7ab4c4a4de2ab22f2c Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 14 Nov 2014 13:43:34 -0500 Subject: [PATCH] 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. --- ChangeLog | 8 ++++++++ libqpdf/QPDFObjectHandle.cc | 2 +- qpdf/qtest/qpdf.test | 7 ++++++- qpdf/qtest/qpdf/page-no-content.out | 8 ++++++++ qpdf/qtest/qpdf/page-no-content.pdf | Bin 0 -> 1362 bytes 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 qpdf/qtest/qpdf/page-no-content.out create mode 100644 qpdf/qtest/qpdf/page-no-content.pdf 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 0000000000000000000000000000000000000000..77b7832a36bf834bb13ccaa52548c08622103200 GIT binary patch literal 1362 zcmcgsOODe(5alDJ!4h{UB(ekA-Tt&KMHWml5fQ(TL}C$T(Xl(hC}ShL1A!G6;0CNX z0vBML5kg`G>){gY5Y?S=3`y7lwq&=ft6sgTdhJH9-MK+;I#%Pu_jf-m3O3}Er&hBG zq$g&w1csJAkm1W`5=cuZG0$fZMV8DG?Wnh_fL6Z96gWWcrb!7STD#14~0UqiIy^Y}R$Mu~aPH&z%PUmCS>%}(bepTJhoY2b1mupKKbINJr$m2A-ot0^Acp#2ZUmXf$u$U+#HeDHhuM0F-wO;i6bgB{dq}@R$xl}N&M5$X} z5&3`Rn>kf!|8f0B0Do@4vXE2D2FfgZbAj)9jt5iN*eL2&Uy#){AEm!#qZqYqV;m>2 z<>#u1|hH&lRjs3K^uYB=!SH zw+*9a?AR=^U5AG5bSmvQraa)>^@NjfTur0q#E+AZI&tDLCc|J7*o?=NN}fyt*G`;h VtbZ4!5`{9&4g+R28b=R1)=x>Gd!YaT literal 0 HcmV?d00001