|
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\RawData\RawDataParser; |
|
36
|
|
|
use Tests\Smalot\PdfParser\TestCase; |
|
37
|
|
|
|
|
38
|
|
|
class RawDataParserHelper extends RawDataParser |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* Expose protected function "getRawObject". |
|
42
|
|
|
*/ |
|
43
|
|
|
public function exposeGetRawObject($pdfData, $offset = 0) |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->getRawObject($pdfData, $offset); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
class RawDataParserTest extends TestCase |
|
50
|
|
|
{ |
|
51
|
|
|
protected function setUp() |
|
52
|
|
|
{ |
|
53
|
|
|
parent::setUp(); |
|
54
|
|
|
|
|
55
|
|
|
$this->fixture = new RawDataParserHelper(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Tests buggy behavior of getRawObject. |
|
60
|
|
|
* |
|
61
|
|
|
* When PDF has corrupted xref table getRawObject may run into an infinite loop. |
|
62
|
|
|
* |
|
63
|
|
|
* @see https://github.com/smalot/pdfparser/issues/372 |
|
64
|
|
|
* @see https://github.com/smalot/pdfparser/pull/377 |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testGetRawObjectIssue372() |
|
67
|
|
|
{ |
|
68
|
|
|
// The following $data content is a minimal example to trigger the infinite loop |
|
69
|
|
|
$data = '<</Producer (eDkºãa˜þõ‚LÅòÕ�PïÙ��)©)>>'; |
|
70
|
|
|
|
|
71
|
|
|
// calling "getRawObject" via "exposeGetRawObject" would result in an infinite loop |
|
72
|
|
|
// if the fix is not there. |
|
73
|
|
|
$result = $this->fixture->exposeGetRawObject($data); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertEquals( |
|
76
|
|
|
[ |
|
77
|
|
|
'<<', |
|
78
|
|
|
[ |
|
79
|
|
|
['/', 'Producer', 11], |
|
80
|
|
|
['(', 'eDkºãa˜þõ‚LÅòÕ�PïÙ��', 52], |
|
81
|
|
|
], |
|
82
|
|
|
52, |
|
83
|
|
|
], |
|
84
|
|
|
$result |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Tests buggy behavior of decodeXrefStream. |
|
90
|
|
|
* |
|
91
|
|
|
* @see https://github.com/smalot/pdfparser/issues/30 |
|
92
|
|
|
* @see https://github.com/smalot/pdfparser/issues/192 |
|
93
|
|
|
* @see https://github.com/smalot/pdfparser/issues/209 |
|
94
|
|
|
* @see https://github.com/smalot/pdfparser/issues/330 |
|
95
|
|
|
* @see https://github.com/smalot/pdfparser/issues/356 |
|
96
|
|
|
* @see https://github.com/smalot/pdfparser/issues/373 |
|
97
|
|
|
* @see https://github.com/smalot/pdfparser/issues/392 |
|
98
|
|
|
* @see https://github.com/smalot/pdfparser/issues/397 |
|
99
|
|
|
*/ |
|
100
|
|
|
public function testDecodeXrefStreamIssue356() |
|
101
|
|
|
{ |
|
102
|
|
|
$filename = $this->rootDir.'/samples/bugs/Issue356.pdf'; |
|
103
|
|
|
|
|
104
|
|
|
$parser = $this->getParserInstance(); |
|
105
|
|
|
$document = $parser->parseFile($filename); |
|
106
|
|
|
$pages = $document->getPages(); |
|
107
|
|
|
|
|
108
|
|
|
$this->assertStringContainsString('Ημερήσια έκθεση επιδημιολογικής', $pages[0]->getText()); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|