mirror of
https://github.com/qpdf/qpdf.git
synced 2024-09-19 08:39:09 +00:00
Remove non-dictionary objects from pages tree
This commit is contained in:
parent
01353e114f
commit
7f2d76b78d
@ -1515,6 +1515,7 @@ class QPDF
|
||||
std::set<QPDFObjGen> resolving;
|
||||
QPDFObjectHandle trailer;
|
||||
std::vector<QPDFObjectHandle> all_pages;
|
||||
bool invalid_page_found{false};
|
||||
std::map<QPDFObjGen, int> pageobj_to_pages_pos;
|
||||
bool pushed_inherited_attributes_to_pages{false};
|
||||
bool ever_pushed_inherited_attributes_to_pages{false};
|
||||
|
@ -40,7 +40,7 @@ std::vector<QPDFObjectHandle> const&
|
||||
QPDF::getAllPages()
|
||||
{
|
||||
// Note that pushInheritedAttributesToPage may also be used to initialize m->all_pages.
|
||||
if (m->all_pages.empty()) {
|
||||
if (m->all_pages.empty() && !m->invalid_page_found) {
|
||||
m->ever_called_get_all_pages = true;
|
||||
QPDFObjGen::set visited;
|
||||
QPDFObjGen::set seen;
|
||||
@ -70,6 +70,10 @@ QPDF::getAllPages()
|
||||
// Ensure we actually found a /Pages object.
|
||||
getAllPagesInternal(pages, visited, seen, false);
|
||||
}
|
||||
if (m->invalid_page_found) {
|
||||
flattenPagesTree();
|
||||
m->invalid_page_found = false;
|
||||
}
|
||||
}
|
||||
return m->all_pages;
|
||||
}
|
||||
@ -100,6 +104,7 @@ QPDF::getAllPagesInternal(
|
||||
auto kid = kids.getArrayItem(i);
|
||||
if (!kid.isDictionary()) {
|
||||
kid.warnIfPossible("Pages tree includes non-dictionary object; ignoring");
|
||||
m->invalid_page_found = true;
|
||||
continue;
|
||||
}
|
||||
if (kid.hasKey("/Kids")) {
|
||||
@ -181,8 +186,12 @@ QPDF::flattenPagesTree()
|
||||
pages.replaceKey("/Kids", QPDFObjectHandle::newArray(m->all_pages));
|
||||
// /Count has not changed
|
||||
if (pages.getKey("/Count").getUIntValue() != len) {
|
||||
if (m->invalid_page_found && pages.getKey("/Count").getUIntValue() > len) {
|
||||
pages.replaceKey("/Count", QPDFObjectHandle::newInteger(toI(len)));
|
||||
} else {
|
||||
throw std::runtime_error("/Count is wrong after flattening pages tree");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user