diff --git a/samples/bugs/Issue727.pdf b/samples/bugs/Issue727.pdf new file mode 100644 index 00000000..1d2f89ae Binary files /dev/null and b/samples/bugs/Issue727.pdf differ diff --git a/tests/PHPUnit/Integration/RawData/RawDataParserTest.php b/tests/PHPUnit/Integration/RawData/RawDataParserTest.php index 7a586932..88d85006 100644 --- a/tests/PHPUnit/Integration/RawData/RawDataParserTest.php +++ b/tests/PHPUnit/Integration/RawData/RawDataParserTest.php @@ -194,4 +194,24 @@ public function testGetXrefDataIssue673(): void self::assertStringContainsString('6 rue des Goutais', $text); } + + /** + * Handle self referencing xref + * + * It seems that some pdf creators output `Prev 0` when there is no previous + * xref + * + * @see https://github.com/smalot/pdfparser/pull/727 + */ + public function testDecodeXrefIssue727(): void + { + $filename = $this->rootDir.'/samples/bugs/Issue727.pdf'; + + // Parsing this document would previously cause an infinite loop + $parser = $this->getParserInstance(); + $document = $parser->parseFile($filename); + $text = $document->getText(); + + self::assertStringContainsString('', $text); + } }