From 05eb5826d8b8beb19e8ec65915af1476e7dd1db3 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 20 Feb 2021 19:16:40 -0500 Subject: Fix isPagesObject and isPageObject There are lots of things with /Kids that are not pages. Repair the pages tree, then do a reliable check. --- libqpdf/QPDFObjectHandle.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index b0ae75f1..6c37829d 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -3039,6 +3039,12 @@ bool QPDFObjectHandle::isPageObject() { // See comments in QPDFObjectHandle.hh. + if (getOwningQPDF() == nullptr) + { + return false; + } + // getAllPages repairs /Type when traversing the page tree. + getOwningQPDF()->getAllPages(); if (! this->isDictionary()) { return false; @@ -3066,8 +3072,16 @@ QPDFObjectHandle::isPageObject() bool QPDFObjectHandle::isPagesObject() { - // Some PDF files have /Type broken on pages. - return (this->isDictionary() && this->hasKey("/Kids")); + if (getOwningQPDF() == nullptr) + { + return false; + } + // getAllPages repairs /Type when traversing the page tree. + getOwningQPDF()->getAllPages(); + return (this->isDictionary() && + this->hasKey("/Type") && + this->getKey("/Type").isName() && + this->getKey("/Type").getName() == "/Pages"); } bool -- cgit v1.2.3-54-g00ecf