Skip to content
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
45 changes: 10 additions & 35 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,14 @@ name: "CI"

on: [push, pull_request]

env:
fail-fast: true

jobs:
phpunit:
name: "PHPUnit (PHP ${{ matrix.php }})"
runs-on: ubuntu-latest

strategy:
matrix:
php:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']

steps:
- name: "Checkout"
Expand Down Expand Up @@ -50,8 +39,7 @@ jobs:

strategy:
matrix:
php:
- "7.1"
php: ['7.1']

steps:
- name: "Checkout"
Expand Down Expand Up @@ -81,8 +69,7 @@ jobs:

strategy:
matrix:
php:
- "7.4"
php: ['7.4']

steps:
- name: "Checkout"
Expand Down Expand Up @@ -112,8 +99,7 @@ jobs:

strategy:
matrix:
php:
- "7.4"
php: ['7.4']

steps:
- name: "Checkout"
Expand Down Expand Up @@ -143,16 +129,7 @@ jobs:

strategy:
matrix:
php:
- "7.1"
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']

steps:
- name: "Checkout"
Expand All @@ -173,9 +150,7 @@ jobs:

strategy:
matrix:
php:
- "7.3"

php: ['7.3']
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
Expand All @@ -201,13 +176,13 @@ jobs:
run: "make run-phpunit"

windows-tests:
name: Windows-Tests with PHP ${{ matrix.php-versions }}
name: Windows-Tests with PHP ${{ matrix.php }}
runs-on: windows-latest

strategy:
fail-fast: true
fail-fast: false
matrix:
php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']

steps:
- name: Checkout
Expand All @@ -216,7 +191,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: ${{ matrix.php }}
ini-values: memory_limit=1G

- name: Install Composer dependencies (root)
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ jobs:

strategy:
matrix:
php:
- "7.4"
php: ['7.4']

steps:
- name: "Checkout"
Expand Down
2 changes: 1 addition & 1 deletion phpunit-windows.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" backupGlobals="false" bootstrap="vendor\autoload.php" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false" displayDetailsOnTestsThatTriggerWarnings="true">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" backupGlobals="false" bootstrap="vendor\autoload.php" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false" displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerDeprecations="true">
<coverage>
<include>
<directory>src</directory>
Expand Down
11 changes: 10 additions & 1 deletion src/Smalot/PdfParser/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,16 @@ public function extractXMPMetadata(string $content): void
$this->metadata = array_merge($this->metadata, $metadata);
}
}
xml_parser_free($xml);

// TODO: remove this if-clause and its content when dropping PHP 7 support
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
// ref: https://www.php.net/manual/en/function.xml-parser-free.php
xml_parser_free($xml);

// to avoid memory leaks; documentation said:
// > it was necessary to also explicitly unset the reference to parser to avoid memory leaks
unset($xml);
}
}

public function getDictionary(): array
Expand Down
30 changes: 29 additions & 1 deletion src/Smalot/PdfParser/RawData/FilterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,35 @@ protected function decodeFilterASCII85Decode(string $data): string
// the value represented by a group of 5 characters should never be greater than 2^32 - 1
$tuple += (($char - 33) * $pow85[$group_pos]);
if (4 == $group_pos) {
$decoded .= \chr($tuple >> 24).\chr($tuple >> 16).\chr($tuple >> 8).\chr($tuple);
// The following if-clauses are an attempt to fix/suppress the following deprecation warning:
// chr(): Providing a value not in-between 0 and 255 is deprecated, this is because a byte value
// must be in the [0, 255] interval. The value used will be constrained using % 256
// I know this is ugly and there might be more fancier ways. If you know one, feel free to provide a pull request.
if (255 < $tuple >> 8) {
$chr8Part = \chr(($tuple >> 8) % 256);
} else {
$chr8Part = \chr($tuple >> 8);
}

if (255 < $tuple >> 16) {
$chr16Part = \chr(($tuple >> 16) % 256);
} else {
$chr16Part = \chr($tuple >> 16);
}

if (255 < $tuple >> 24) {
$chr24Part = \chr(($tuple >> 24) % 256);
} else {
$chr24Part = \chr($tuple >> 24);
}

if (255 < $tuple) {
$chrTuple = \chr($tuple % 256);
} else {
$chrTuple = \chr($tuple);
}

$decoded .= $chr24Part . $chr16Part . $chr8Part . $chrTuple;
$tuple = 0;
$group_pos = 0;
} else {
Expand Down
25 changes: 22 additions & 3 deletions tests/PHPUnit/Integration/PDFObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,14 @@ public function testFormatContent(): void
$expected = str_replace(["\r\n", "\n"], ["\n", "\r\n"], $expected);

$formatContent = new \ReflectionMethod('Smalot\PdfParser\PDFObject', 'formatContent');
$formatContent->setAccessible(true);

// TODO: remove this if-clause when dropping 8.0.x support
// From documentation > http://php.net/manual/en/reflectionproperty.setaccessible.php:
// As of PHP 8.1.0, calling this method has no effect; all properties are accessible by default.
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
$formatContent->setAccessible(true);
}

$cleaned = $formatContent->invoke($this->getPdfObjectInstance(new Document()), $content);

$this->assertEquals($expected, $cleaned);
Expand Down Expand Up @@ -303,7 +310,13 @@ public function testFormatContent(): void
public function testFormatContentIssue709()
{
$formatContent = new \ReflectionMethod('Smalot\PdfParser\PDFObject', 'formatContent');
$formatContent->setAccessible(true);

// TODO: remove this if-clause when dropping 8.0.x support
// From documentation > http://php.net/manual/en/reflectionproperty.setaccessible.php:
// As of PHP 8.1.0, calling this method has no effect; all properties are accessible by default.
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
$formatContent->setAccessible(true);
}

$content = '(String \\\\\\(string)Tj '.str_repeat('(Test)Tj ', 4500);
$cleaned = $formatContent->invoke($this->getPdfObjectInstance(new Document()), $content);
Expand All @@ -319,7 +332,13 @@ public function testFormatContentIssue709()
public function testFormatContentInlineImages(): void
{
$formatContent = new \ReflectionMethod('Smalot\PdfParser\PDFObject', 'formatContent');
$formatContent->setAccessible(true);

// TODO: remove this if-clause when dropping 8.0.x support
// From documentation > http://php.net/manual/en/reflectionproperty.setaccessible.php:
// As of PHP 8.1.0, calling this method has no effect; all properties are accessible by default.
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
$formatContent->setAccessible(true);
}

$cleaned = $formatContent->invoke(
$this->getPdfObjectInstance(new Document()),
Expand Down
Loading