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

php8.3-imagick PHP Fatal error when trying to read a PDF file (FPM only) #2084

Open
3 tasks done
onlime opened this issue Feb 26, 2024 · 0 comments
Open
3 tasks done

Comments

@onlime
Copy link

onlime commented Feb 26, 2024

Frequently asked questions

  • I have read Frequently Asked Questions
  • I have looked at the list of the existing issues (including closed issues) and searched if my issue has been already reported
  • I have tried to resolve the issue myself and will describe what I did in clear and concise manner

Describe the bug

I cannot get PDF to JPG conversion running under PHP-FPM using latest PHP 8.3.3 / imagick 3.7.0 (php8.3-imagick package) / Imagemagick 6.9.11.60 on a Debian Bookworm 12.5 system. The below script to reproduce works fine with any demo.pdf file in the same directory if run with php-cli from command line, but not if run from the browser with php-fpm, failing on readImage():

PHP Fatal error:  Uncaught ImagickException: Invalid filename provided

All other image to image conversions work fine. Just seems to be an issue with PDF files.

It also works fine under PHP 8.2.16 (php8.2-imagick package), with exact same FPM configuration.

I would like to point out that I was unable to reproduce this under Homebrew PHP 8.3 install (see Additional context section below) / PHP-FPM, so I assume this issue only occurs on DEB.SURY.ORG php8.3-imagick package. Please correct me if I am wrong and this is a known issue of ImageMagick 3.7.0 under PHP 8.3

To Reproduce

Create a demo.php file with the following content:

<?php

$image = new imagick();
$image->readImage( __DIR__ . '/demo.pdf[0]');
$image->setImageFormat('jpg');
$image->writeImage(__DIR__ . '/demo.jpg');

put some demo.pdf into the same directory and run it from CLI:

$ php demo.php

the resulting demo.jpg will get correctly generated. But not if you run the script from PHP-FPM via your browser, getting the following error instead:

PHP Fatal error:  Uncaught ImagickException: Invalid filename provided in (...)/test.php:4
Stack trace:
#0 (...)/test.php(4): Imagick->readImage('')
#1 {main}
  thrown in (...)/test.php on line 4

Your understanding of what is happening

Imagick seems to prevent access to the demo.pdf file or can somehow not access the underlying gs binary for the image conversion.

What steps did you take to resolve issue yourself before reporting it here

What I checked so far:

  • Checked issues on upstream https://github.com/Imagick/imagick
  • Imagick extension is installed as specific version release, php8.3-imagick package from DEB.SURY.ORG
  • Imagick is compiled with the same Imagemagick version as the library version on the system, ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25 (according to phpinfo, running over PHP-FPM)
  • diff /etc/php/8.3/cli/php.ini /etc/php/8.3/fpm/php.ini - no relevant diff except memory_limit 1024M (CLI) vs. 256M (FPM)
  • Ghostscript is installed and which gs resolves to /usr/bin/gs
  • phpinfo via FPM shows $_SERVER['PATH'] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' – so /usr/bin is in the $PATH and accessible by the FPM pool's user (also checked ACLs with getfacl, no restrictions there!)
  • Followed recommendations on https://stackoverflow.com/a/51067920/5982842 and https://copyprogramming.com/howto/can-t-read-pdf-file-with-imagemagick and replaced all &quot;gs&quot; in /etc/ImageMagick-6/delegates.xml by absolute paths &quot;/usr/bin/gs&quot;
  • Checked /etc/ImageMagick-6/policy.xml: no restrictions for PDF files (see below)
$ grep PDF /etc/ImageMagick-6/policy.xml
  <!-- <policy domain="module" rights="none" pattern="{PS,PDF,XPS}" /> -->
  <!-- <policy domain="coder" rights="none" pattern="PDF" /> -->

Expected behavior

The demo.jpg thumbnail should get created from the PDF's first page without any errors.

Distribution:

  • OS: Debian 12.5
  • Architecture: amd64
  • Repository: packages.sury.org

Package(s):

$ apt-cache policy php php8.3-imagick php8.3-fpm imagemagick php8.2-imagick php8.2-fpm
php:
  Installed: (none)
  Candidate: 2:8.3+94+0~20240205.51+debian12~1.gbp6faa2e
  Version table:
     2:8.3+94+0~20240205.51+debian12~1.gbp6faa2e 500
        500 https://packages.sury.org/php bookworm/main amd64 Packages
     2:8.2+93 500
        500 https://debian.ethz.ch/debian bookworm/main amd64 Packages
php8.3-imagick:
  Installed: 3.7.0-4+0~20231125.43+debian12~1.gbpbf7e27
  Candidate: 3.7.0-4+0~20231125.43+debian12~1.gbpbf7e27
  Version table:
 *** 3.7.0-4+0~20231125.43+debian12~1.gbpbf7e27 500
        500 https://packages.sury.org/php bookworm/main amd64 Packages
        100 /var/lib/dpkg/status
php8.3-fpm:
  Installed: 8.3.3-1+0~20240216.17+debian12~1.gbp87e37b
  Candidate: 8.3.3-1+0~20240216.17+debian12~1.gbp87e37b
  Version table:
 *** 8.3.3-1+0~20240216.17+debian12~1.gbp87e37b 500
        500 https://packages.sury.org/php bookworm/main amd64 Packages
        100 /var/lib/dpkg/status
imagemagick:
  Installed: 8:6.9.11.60+dfsg-1.6+deb12u1
  Candidate: 8:6.9.11.60+dfsg-1.6+deb12u1
  Version table:
 *** 8:6.9.11.60+dfsg-1.6+deb12u1 500
        500 https://security.debian.org/debian-security bookworm-security/main amd64 Packages
        100 /var/lib/dpkg/status
     8:6.9.11.60+dfsg-1.6 500
        500 https://debian.ethz.ch/debian bookworm/main amd64 Packages
php8.2-imagick:
  Installed: 3.7.0-4+0~20231125.43+debian12~1.gbpbf7e27
  Candidate: 3.7.0-4+0~20231125.43+debian12~1.gbpbf7e27
  Version table:
 *** 3.7.0-4+0~20231125.43+debian12~1.gbpbf7e27 500
        500 https://packages.sury.org/php bookworm/main amd64 Packages
        100 /var/lib/dpkg/status
     3.7.0-4 500
        500 https://debian.ethz.ch/debian bookworm/main amd64 Packages
php8.2-fpm:
  Installed: 8.2.16-1+0~20240216.40+debian12~1.gbp6cbea3
  Candidate: 8.2.16-1+0~20240216.40+debian12~1.gbp6cbea3
  Version table:
 *** 8.2.16-1+0~20240216.40+debian12~1.gbp6cbea3 500
        500 https://packages.sury.org/php bookworm/main amd64 Packages
        100 /var/lib/dpkg/status
     8.2.7-1~deb12u1 500
        500 https://debian.ethz.ch/debian bookworm/main amd64 Packages
        500 https://security.debian.org/debian-security bookworm-security/main amd64 Packages

Additional context

I have also tried to reproduce this issue on macOS Homebrew PHP 8.3.3 running as PHP-FPM under Nginx (using Laravel Valet), imagick installed via PECL. phpinfo shows ImageMagick 7.1.1-29 Q16-HDRI aarch64 21991 and the PDF-to-JPG conversion via FPM (using the same demo.php script as above) works just fine without any errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant