Skip to content

Commit

Permalink
Merge pull request #192 from Setasign/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
JanSlabon authored Dec 5, 2023
2 parents ecf0459 + 889df5d commit d11732a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
2 changes: 2 additions & 0 deletions local-tests/concatenate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set_time_limit(120);
ini_set('memory_limit', '512M');
error_reporting(E_ALL);
ini_set('display_errors', 1);


$fpdiLegacy = __DIR__ . '/../../FPDI/classes/fpdi.php';
Expand Down
2 changes: 1 addition & 1 deletion src/FpdiTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function setMinPdfVersion($pdfVersion)
*/
protected function getPdfParserInstance(StreamReader $streamReader, array $parserParams = [])
{
// note: if you get an exception here - turn off errors/warnings on not found for your autoloader.
// note: if you get an exception here - turn off errors/warnings on not found classes for your autoloader.
// psr-4 (https://www.php-fig.org/psr/psr-4/) says: Autoloader implementations MUST NOT throw
// exceptions, MUST NOT raise errors of any level, and SHOULD NOT return a value.
/** @noinspection PhpUndefinedClassInspection */
Expand Down
2 changes: 1 addition & 1 deletion src/PdfParser/CrossReference/CrossReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct(PdfParser $parser, $fileHeaderOffset = 0)
// sometimes the file header offset is part of the byte offsets, so let's retry by resetting it to zero.
if ($e->getCode() === CrossReferenceException::INVALID_DATA && $this->fileHeaderOffset !== 0) {
$this->fileHeaderOffset = 0;
$reader = $this->readXref($offset + $this->fileHeaderOffset);
$reader = $this->readXref($offset);
} else {
throw $e;
}
Expand Down
17 changes: 3 additions & 14 deletions src/PdfParser/Filter/Flate.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,10 @@ public function decode($data)
return $data;
}

// Try this fallback
$tries = 0;
// Try this fallback (remove the zlib stream header)
$data = @(gzinflate(substr($oData, 2)));

$oDataLen = strlen($oData);
while ($tries < 6 && ($data === false || (strlen($data) < ($oDataLen - $tries - 1)))) {
$data = @(gzinflate(substr($oData, $tries)));
$tries++;
}

// let's use this fallback only if the $data is longer than the original data
if (strlen($data) > ($oDataLen - $tries - 1)) {
return $data;
}

if (!$data) {
if ($data === false) {
throw new FlateException(
'Error while decompressing stream.',
FlateException::DECOMPRESS_ERROR
Expand Down
10 changes: 9 additions & 1 deletion tests/functional/PdfParser/Filter/FlateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public function decodeProvider()
[
file_get_contents(__DIR__ . '/_files/Flate/special.bin'),
file_get_contents(__DIR__ . '/_files/Flate/special-decoded.bin'),
],
[
"\x48\x89\x03\x00",
''
]
);
}
Expand All @@ -55,7 +59,11 @@ public function testDecode($in, $expected)

$decoded = $filter->decode($in);

$this->assertStringStartsWith($expected, $decoded);
if ($expected === '') {
$this->assertSame('', $decoded);
} else {
$this->assertStringStartsWith($expected, $decoded);
}
}

public function testEmptyString()
Expand Down

0 comments on commit d11732a

Please sign in to comment.