Skip to content

Commit

Permalink
Merge pull request #100 from Setasign/development
Browse files Browse the repository at this point in the history
Throw explicit exception in case of invalid object type at xref offset.
  • Loading branch information
JanSlabon authored Mar 23, 2020
2 parents 368d7b8 + 2a20af4 commit 5277614
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/PdfParser/CrossReference/CrossReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,16 @@ protected function initReaderInstance($initValue)
}

if ($initValue instanceof PdfIndirectObject) {
// check for encryption
$stream = PdfStream::ensure($initValue->value);
try {
$stream = PdfStream::ensure($initValue->value);

} catch (PdfTypeException $e) {
throw new CrossReferenceException(
'Invalid object type at xref reference offset.',
CrossReferenceException::INVALID_DATA,
$e
);
}

$type = PdfDictionary::get($stream->value, 'Type');
if ($type->value !== 'XRef') {
Expand Down
26 changes: 26 additions & 0 deletions tests/functional/PdfParser/CrossReference/CrossReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,4 +597,30 @@ public function testBehaviourWithHeaderOffsetWhichIsUsedInRealByteOffsets()

$this->assertEquals(PdfIndirectObject::create(1, 0, PdfDictionary::create([])), $object);
}

/**
* @expectedException \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException
* @expectedExceptionCode \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException::INVALID_DATA
*/
public function testBehaviourWithWrongObjectTypeAttXrefOffset()
{
$pdf = "%PDF-1.7\n" .
"%\xE2\xE3\xCF\xD3\n" .
"1 0 obj\n" .
"<<>>" .
"xref\n" .
"0 2\r\n" .
"0000000000 65535 f\r\n" .
"0000000015 00000 n\r\n" .
"trailer\n" .
"<</Size 2 /Root 1 0 R>>\n" .
"startxref\n" .
"15\n" . //
"%%EOF";

$stream = StreamReader::createByString($pdf);
$parser = new PdfParser($stream);
$xref = new CrossReference($parser);
$xref->getTrailer();
}
}

0 comments on commit 5277614

Please sign in to comment.