oerdnj / deb.sury.org

Public bugreports for anything ppa:ondrej/*
821 stars 25 forks source link

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

Open onlime opened 7 months ago

onlime commented 7 months ago

Frequently asked questions

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:

$ 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:

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.