pdfparser
pdfparser copied to clipboard
RawDataParser->getXrefData not fully covered by tests
I had an Exception throw by RawDataParser->getXrefData, I didn't debug this case yet, but I noticed that there's an elseif not covered by tests... I left a var_dump inside the elseif and I ran phpunit and this var_dump didn't show on terminal (I left a var_dump outside this elseif after just to be sure that would be shown on terminal)
This elseif is not covered (RawDataParser.php:822)
elseif ($startxrefPreg) {
// startxref found
$startxref = $matches[1][0];
}
PS: I will try to debug it later, I am just opening an issue for the record
On RawDataParser:822, $matches should be the value attributed by line 796 but on line 817 there's a preg_match that reassign the value of $matches
After I fixed it, I got a infinite loop between RawDataParser->decodeXref() and RawDataParser->getXrefData()
I don't know how to fix it
protected function getXrefData($pdfData, $offset = 0, $xref = [])
{
$startxrefPreg = preg_match(
'/[\r\n]startxref[\s]*[\r\n]+([0-9]+)[\s]*[\r\n]+%%EOF/i',
$pdfData,
$matches,
\PREG_OFFSET_CAPTURE,
$offset
);
if (0 == $offset) {
// find last startxref
$pregResult = preg_match_all(
'/[\r\n]startxref[\s]*[\r\n]+([0-9]+)[\s]*[\r\n]+%%EOF/i',
$pdfData, $matches,
\PREG_SET_ORDER,
$offset
);
if (0 == $pregResult) {
throw new Exception('Unable to find startxref');
}
$matches = array_pop($matches);
$startxref = $matches[1];
} elseif (strpos($pdfData, 'xref', $offset) == $offset) {
// Already pointing at the xref table
$startxref = $offset;
} elseif (preg_match('/([0-9]+[\s][0-9]+[\s]obj)/i', $pdfData, $matches, \PREG_OFFSET_CAPTURE, $offset)) {
// Cross-Reference Stream object
$startxref = $offset;
} elseif ($startxrefPreg) {
// startxref found
$startxref = $matches[1][0];
} else {
throw new Exception('Unable to find startxref');
}
After I fixed it, I got a infinite loop between RawDataParser->decodeXref() and RawDataParser->getXrefData()
this seems to be related to one of the memory leak issues outlined in #104