Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/PdfReader/PdfReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ protected function readPages($readAll = false)
return;
}

$readPages = function ($kids, $count) use (&$readPages, $readAll) {
$expectedPageCount = $this->getPageCount();
$readPages = function ($kids, $count) use (&$readPages, $readAll, $expectedPageCount) {
$kids = PdfArray::ensure($kids);
$isLeaf = ($count->value === \count($kids->value));

Expand All @@ -222,6 +223,11 @@ protected function readPages($readAll = false)
} else {
$this->pages[] = $object;
}

// stop if all pages are read - faulty documents exists with additional entries with invalid data.
if (count($this->pages) === $expectedPageCount) {
break;
}
}
};

Expand Down
Binary file not shown.
26 changes: 26 additions & 0 deletions tests/functional/PdfReader/PdfReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public function getPageCountProvider()
13
];

$data[] = [
$path . '/specials/page-trees/PageTreeWithInvalidTypeAndMisslLeadingCount.pdf',
1
];

return $data;
}

Expand Down Expand Up @@ -835,6 +840,27 @@ public function getPageProvider()
]
];

$data[] = [
$path . '/specials/page-trees/PageTreeWithInvalidTypeAndMisslLeadingCount.pdf',
[
1 => PdfIndirectObject::create(
1,
0,
PdfDictionary::create([
'Type' => PdfName::create('Page'),
'MediaBox' => PdfArray::create([
PdfNumeric::create(0),
PdfNumeric::create(0),
PdfNumeric::create(595.28),
PdfNumeric::create(841.89)
]),
'Resources' => PdfDictionary::create(),
'Parent' => PdfIndirectObjectReference::create(3, 0),
])
)
]
];

return $data;
}

Expand Down