Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RawDataParser->getXrefData not fully covered by tests #436

Open
LucianoHanna opened this issue Jun 15, 2021 · 2 comments
Open

RawDataParser->getXrefData not fully covered by tests #436

LucianoHanna opened this issue Jun 15, 2021 · 2 comments

Comments

@LucianoHanna
Copy link
Contributor

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

@LucianoHanna
Copy link
Contributor Author

LucianoHanna commented Jun 15, 2021

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');
        }

@Connum
Copy link
Contributor

Connum commented Jul 20, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants