Fatal Error when parsing some PDFs
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.7k
- Forks
- 579
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
- PHP Version: 7.4
- PDFParser Version: 2.7.0 ( + 2.8.0-RC2)
Description:
Very recently started getting the following Fatal Error when trying to parse some PDF files...
PHP Fatal error: Uncaught Exception: Invalid object reference for $obj. in >../vendor/smalot/pdfparser/src/Smalot/PdfParser/RawData/RawDataParser.php:529
Stack trace:
#0 ../vendor/smalot/pdfparser/src/Smalot/PdfParser/RawData/RawDataParser.php(240): >Smalot\PdfParser\RawData\RawDataParser->getIndirectObject('%PDF-1.4\r\n%\xF9\xFA\x9A\xE7...', Array, '4', 203, true)
#1 ../vendor/smalot/pdfparser/src/Smalot/PdfParser/RawData/RawDataParser.php(905): >Smalot\PdfParser\RawData\RawDataParser->decodeXrefStream('%PDF-1.4\r\n%\xF9\xFA\x9A\xE7...', 203, Array)
#2 ../vendor/smalot/pdfparser/src/Smalot/PdfParser/RawData/RawDataParser.php(216): >Smalot\PdfParser\RawData\RawDataParser->getXrefData('%PDF-1.4\r\n%\xF9\xFA\x9A\xE7...', 203, Array)
#3 ../vendor/smalot/pdfparser/src/Smalot/PdfParser/RawData/RawDataParser.php(902): Smalot\PdfParser in >../vendor/smalot/pdfparser/src/Smalot/PdfParser/RawData/RawDataParser.php on line 529"
PDF input
I would be willing to provide a copy of the PDF if I can do so privately.
Expected output & actual output
The expected output of my code is the contents of the PDF parsed into a string of text and ultimately saved to a variable, instead there is a fatal error on certain PDF files and I really can't tell why.
Code
$ext = pathinfo($path, PATHINFO_EXTENSION);
if ( $ext == 'pdf' || $ext == 'PDF') {
$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile($path);
$text = $pdf->getText();
}
return $text;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/Smalot/PdfParser/RawData/RawDataParser.php at the reported failures around lines 529, 240, and 905. Obtain the reporter's PDF if possible, run the provided parseFile() example, and trace the xref-stream handling; done means the affected PDF parses without a fatal invalid-object-reference error and produces text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100