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

Development #192

Merged
merged 7 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading