-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix infite loop when xref table corrupted (#377)
* Fix infite loop when xref table corrupted Issue #372 * added a test which triggers the infinite loop it proofs the fix in RawDataParser prevents the infinite loop. thanks to @partulaj: #372 (comment) * fixed coding style issues Co-authored-by: Konrad Abicht <[email protected]>
- Loading branch information
Showing
2 changed files
with
126 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
/** | ||
* @file This file is part of the PdfParser library. | ||
* | ||
* @author Konrad Abicht <[email protected]> | ||
* @date 2020-06-01 | ||
* | ||
* @author Sébastien MALOT <[email protected]> | ||
* @date 2017-01-03 | ||
* | ||
* @license LGPLv3 | ||
* @url <https://github.com/smalot/pdfparser> | ||
* | ||
* PdfParser is a pdf library written in PHP, extraction oriented. | ||
* Copyright (C) 2017 - Sébastien MALOT <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. | ||
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>. | ||
*/ | ||
|
||
namespace Tests\Smalot\PdfParser\Integration\RawData; | ||
|
||
use Smalot\PdfParser\RawData\RawDataParser; | ||
use Tests\Smalot\PdfParser\TestCase; | ||
|
||
class RawDataParserHelper extends RawDataParser | ||
{ | ||
/** | ||
* Expose protected function "getRawObject". | ||
*/ | ||
public function exposeGetRawObject($pdfData, $offset = 0) | ||
{ | ||
return $this->getRawObject($pdfData, $offset); | ||
} | ||
} | ||
|
||
class RawDataParserTest extends TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->fixture = new RawDataParserHelper(); | ||
} | ||
|
||
/** | ||
* Tests buggy behavior of getRawObject. | ||
* | ||
* When PDF has corrupted xref table getRawObject may run into an infinite loop. | ||
* | ||
* @see https://github.com/smalot/pdfparser/issues/372 | ||
* @see https://github.com/smalot/pdfparser/pull/377 | ||
*/ | ||
public function testGetRawObjectIssue372() | ||
{ | ||
// The following $data content is a minimal example to trigger the infinite loop | ||
$data = '<</Producer (eDkºãa˜þõ‚LÅòÕ�PïÙ��)©)>>'; | ||
|
||
// calling "getRawObject" via "exposeGetRawObject" would result in an infinite loop | ||
// if the fix is not there. | ||
$result = $this->fixture->exposeGetRawObject($data); | ||
|
||
$this->assertEquals( | ||
[ | ||
'<<', | ||
[ | ||
['/', 'Producer', 11], | ||
['(', 'eDkºãa˜þõ‚LÅòÕ�PïÙ��', 52], | ||
], | ||
52, | ||
], | ||
$result | ||
); | ||
} | ||
} |