Test Failed
Pull Request — master (#479)
by
unknown
01:38
created

RawDataParserHelper::exposeGetRawObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * @file This file is part of the PdfParser library.
5
 *
6
 * @author  Konrad Abicht <[email protected]>
7
 * @date    2020-06-01
8
 *
9
 * @author  Sébastien MALOT <[email protected]>
10
 * @date    2017-01-03
11
 *
12
 * @license LGPLv3
13
 * @url     <https://github.com/smalot/pdfparser>
14
 *
15
 *  PdfParser is a pdf library written in PHP, extraction oriented.
16
 *  Copyright (C) 2017 - Sébastien MALOT <[email protected]>
17
 *
18
 *  This program is free software: you can redistribute it and/or modify
19
 *  it under the terms of the GNU Lesser General Public License as published by
20
 *  the Free Software Foundation, either version 3 of the License, or
21
 *  (at your option) any later version.
22
 *
23
 *  This program is distributed in the hope that it will be useful,
24
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 *  GNU Lesser General Public License for more details.
27
 *
28
 *  You should have received a copy of the GNU Lesser General Public License
29
 *  along with this program.
30
 *  If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
31
 */
32
33
namespace Tests\Smalot\PdfParser\Integration\RawData;
34
35
use Smalot\PdfParser\Config;
36
use Smalot\PdfParser\RawData\RawDataParser;
37
use Tests\Smalot\PdfParser\TestCase;
38
39
class RawDataParserHelper extends RawDataParser
40
{
41
    /**
42
     * Expose protected function "getRawObject".
43
     */
44
    public function exposeGetRawObject($pdfData, $offset = 0)
45
    {
46
        return $this->getRawObject($pdfData, $offset);
47
    }
48
}
49
50
class RawDataParserTest extends TestCase
51
{
52
    protected function setUp(): void
53
    {
54
        parent::setUp();
55
56
        $this->fixture = new RawDataParserHelper([], new Config());
57
    }
58
59
    /**
60
     * Tests buggy behavior of getRawObject.
61
     *
62
     * When PDF has corrupted xref table getRawObject may run into an infinite loop.
63
     *
64
     * @see https://github.com/smalot/pdfparser/issues/372
65
     * @see https://github.com/smalot/pdfparser/pull/377
66
     */
67
    public function testGetRawObjectIssue372()
68
    {
69
        // The following $data content is a minimal example to trigger the infinite loop
70
        $data = '<</Producer (eDkºãa˜þõ‚LÅòÕ�PïÙ��)©)>>';
71
72
        // calling "getRawObject" via "exposeGetRawObject" would result in an infinite loop
73
        // if the fix is not there.
74
        $result = $this->fixture->exposeGetRawObject($data);
75
76
        $this->assertEquals(
77
            [
78
                '<<',
79
                [
80
                    ['/', 'Producer', 11],
81
                    ['(', 'eDkºãa˜þõ‚LÅòÕ�PïÙ��', 52],
82
                ],
83
                52,
84
            ],
85
            $result
86
        );
87
    }
88
89
    /**
90
     * Tests buggy behavior of decodeXrefStream.
91
     *
92
     * @see https://github.com/smalot/pdfparser/issues/30
93
     * @see https://github.com/smalot/pdfparser/issues/192
94
     * @see https://github.com/smalot/pdfparser/issues/209
95
     * @see https://github.com/smalot/pdfparser/issues/330
96
     * @see https://github.com/smalot/pdfparser/issues/356
97
     * @see https://github.com/smalot/pdfparser/issues/373
98
     * @see https://github.com/smalot/pdfparser/issues/392
99
     * @see https://github.com/smalot/pdfparser/issues/397
100
     */
101
    public function testDecodeXrefStreamIssue356()
102
    {
103
        $filename = $this->rootDir.'/samples/bugs/Issue356.pdf';
104
105
        $parser = $this->getParserInstance();
106
        $document = $parser->parseFile($filename);
107
        $pages = $document->getPages();
108
109
        $this->assertStringContainsString('Ημερήσια έκθεση επιδημιολογικής', $pages[0]->getText());
110
    }
111
112
    public function testDecodeObjectHeaderIssue405()
113
    {
114
        $filename = $this->rootDir.'/samples/bugs/Issue405.pdf';
115
116
        $parser = $this->getParserInstance();
117
        $document = $parser->parseFile($filename);
118
        $pages = $document->getPages();
119
120
        $this->assertStringContainsString('Bug fix: PR #405', $pages[0]->getText());
121
    }
122
123
    /**
124
     * Tests buggy behavior of decodeXrefStream.
125
     *
126
     * When PDF has more than one entry in the /Index area (for example by changing the document description), only the first entry is used.
127
     *
128
     * @see https://github.com/smalot/pdfparser/pull/479
129
     */
130
    public function testDecodeXrefStreamIssue479()
131
        $filename = $this->rootDir.'/samples/bugs/Issue479.pdf';
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_VARIABLE, expecting '{' or ';' on line 131 at column 8
Loading history...
132
133
        $parser = $this->getParserInstance();
134
        $document = $parser->parseFile($filename);
135
        $details = $document->getDetails();
136
137
        $this->assertArrayHasKey('Subject', $details);
138
    }
139
140
}
141