silverstripe / silverstripe-asset-admin

Silverstripe assets gallery for asset management
BSD 3-Clause "New" or "Revised" License
20 stars 79 forks source link

Trying to get EXIF info from PNG images #791

Closed michalkleiner closed 6 years ago

michalkleiner commented 6 years ago

With Exif extension enabled on the server, when uploading a PNG image, the intervention backend is trying to get EXIF data from the file and it fails.

ERROR [Emergency]: Uncaught ErrorException: exif_read_data(interventionimage_Rrn0zU.png): File not supported
IN POST /admin/pages/edit/EditForm/28/field/ElementalArea/add-multi-class/Chrometoaster-Elemental-Model-FullWidthImageBlock/ItemEditForm/field/Image/upload
Line 27 in /home/webspace/alf.branz.co.nz/app/htdocs-20180605/vendor/intervention/image/src/Intervention/Image/Commands/ExifCommand.php

Source
======
  18:          if ( ! function_exists('exif_read_data')) {
  19:              throw new \Intervention\Image\Exception\NotSupportedException(
  20:                  "Reading Exif data is not supported by this PHP installation."
  21:              );
  22:          }
  23:  
  24:          $key = $this->argument(0)->value();
  25:  
  26:          // try to read exif data from image file
* 27:          $data = @exif_read_data($image->dirname .'/'. $image->basename);
  28:  
  29:          if (! is_null($key) && is_array($data)) {
  30:              $data = array_key_exists($key, $data) ? $data[$key] : false;
  31:          }
  32:  
  33:          $this->setOutput($data);

Trace
=====
{closure}(2, exif_read_data(interventionimage_Rrn0zU.png): File not supported, /home/webspace/alf.branz.co.nz/app/htdocs-20180605/vendor/intervention/image/src/Intervention/Image/Commands/ExifCommand.php, 27, Array)

exif_read_data(/tmp/silverstripe-cache-php7.1.18-1+ubuntu14.04.1+deb.sury.org+1-home-webspace-alf.branz.co.nz-app-htdocs-20180605/www-data/interventionimage_Rrn0zU.png)
ExifCommand.php:27

Intervention\Image\Commands\ExifCommand->execute()
AbstractDriver.php:92

Intervention\Image\AbstractDriver->executeCommand(, exif, Array)
Image.php:106

Intervention\Image\Image->__call(exif, Array)
OrientateCommand.php:15

Intervention\Image\Commands\OrientateCommand->execute()
AbstractDriver.php:92

Intervention\Image\AbstractDriver->executeCommand(, orientate, Array)
Image.php:106

Intervention\Image\Image->__call(orientate, Array)
InterventionBackend.php:260

SilverStripe\Assets\InterventionBackend->getImageResource()
ImageManipulation.php:819

SilverStripe\Assets\File->SilverStripe\Assets\{closure}(SilverStripe\Assets\Flysystem\FlysystemAssetStore, Uploads/hotdog2.png, 476eefb950b264341a24a821380357cc35663811, FitMaxWzYwLDYwXQ)

call_user_func(Closure, SilverStripe\Assets\Flysystem\FlysystemAssetStore, Uploads/hotdog2.png, 476eefb950b264341a24a821380357cc35663811, FitMaxWzYwLDYwXQ)
ImageManipulation.php:902

SilverStripe\Assets\File->manipulate(FitMaxWzYwLDYwXQ, Closure)
ImageManipulation.php:858

SilverStripe\Assets\File->manipulateImage(FitMaxWzYwLDYwXQ, Closure)
ImageManipulation.php:403

SilverStripe\Assets\File->FitMax(60, 60)
ThumbnailGenerator.php:97

SilverStripe\AssetAdmin\Model\ThumbnailGenerator->generateThumbnail(SilverStripe\Assets\Image, 60, 60)
ThumbnailGenerator.php:72

SilverStripe\AssetAdmin\Model\ThumbnailGenerator->generateThumbnailLink(SilverStripe\Assets\Image, 60, 60)
AssetAdmin.php:1201

SilverStripe\AssetAdmin\Controller\AssetAdmin->generateThumbnails(SilverStripe\Assets\Image, 1)
AssetAdmin.php:1160

SilverStripe\AssetAdmin\Controller\AssetAdmin->getObjectFromData(SilverStripe\Assets\Image)
UploadField.php:163

SilverStripe\AssetAdmin\Forms\UploadField->upload(SilverStripe\Control\HTTPRequest)
RequestHandler.php:319

SilverStripe\Control\RequestHandler->handleAction(SilverStripe\Control\HTTPRequest, upload)
RequestHandler.php:201

SilverStripe\Control\RequestHandler->handleRequest(SilverStripe\Control\HTTPRequest)
RequestHandler.php:225

SilverStripe\Control\RequestHandler->handleRequest(SilverStripe\Control\HTTPRequest)
RequestHandler.php:225

SilverStripe\Control\RequestHandler->handleRequest(SilverStripe\Control\HTTPRequest)
GridField.php:1047

SilverStripe\Forms\GridField\GridField->handleRequest(SilverStripe\Control\HTTPRequest)
RequestHandler.php:225

SilverStripe\Control\RequestHandler->handleRequest(SilverStripe\Control\HTTPRequest)
RequestHandler.php:225

SilverStripe\Control\RequestHandler->handleRequest(SilverStripe\Control\HTTPRequest)
Controller.php:212

SilverStripe\Control\Controller->handleRequest(SilverStripe\Control\HTTPRequest)
LeftAndMain.php:752

SilverStripe\Admin\LeftAndMain->handleRequest(SilverStripe\Control\HTTPRequest)
AdminRootController.php:123

SilverStripe\Admin\AdminRootController->handleRequest(SilverStripe\Control\HTTPRequest)
Director.php:361

SilverStripe\Control\Director->SilverStripe\Control\{closure}(SilverStripe\Control\HTTPRequest)
VersionedHTTPMiddleware.php:40

SilverStripe\Versioned\VersionedHTTPMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62

SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
BasicAuthMiddleware.php:68

SilverStripe\Security\BasicAuthMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62

SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
AuthenticationMiddleware.php:61

SilverStripe\Security\AuthenticationMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62

SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
TrailingSlashRedirector.php:38

Axllent\TrailingSlash\Middleware\TrailingSlashRedirector->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62

SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
CanonicalURLMiddleware.php:155

SilverStripe\Control\Middleware\CanonicalURLMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62

SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
FlushMiddleware.php:26

SilverStripe\Control\Middleware\FlushMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62

SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
RequestProcessor.php:66

SilverStripe\Control\RequestProcessor->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62

SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
SessionMiddleware.php:20

SilverStripe\Control\Middleware\SessionMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62

SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
AllowedHostsMiddleware.php:60

SilverStripe\Control\Middleware\AllowedHostsMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62

SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
TrustedProxyMiddleware.php:176

SilverStripe\Control\Middleware\TrustedProxyMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62

SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
SSOSessionExtractor.php:28

Chrometoaster\MyBRANZ\SSOSessionExtractor->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62

SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
HTTPMiddlewareAware.php:65

SilverStripe\Control\Director->callMiddleware(SilverStripe\Control\HTTPRequest, Closure)
Director.php:370

SilverStripe\Control\Director->handleRequest(SilverStripe\Control\HTTPRequest)
HTTPApplication.php:48

SilverStripe\Control\HTTPApplication->SilverStripe\Control\{closure}(SilverStripe\Control\HTTPRequest)

call_user_func(Closure, SilverStripe\Control\HTTPRequest)
HTTPApplication.php:66

SilverStripe\Control\HTTPApplication->SilverStripe\Control\{closure}(SilverStripe\Control\HTTPRequest)

call_user_func(Closure, SilverStripe\Control\HTTPRequest)
ErrorControlChainMiddleware.php:56

SilverStripe\Core\Startup\ErrorControlChainMiddleware->SilverStripe\Core\Startup\{closure}(SilverStripe\Core\Startup\ErrorControlChain)

call_user_func(Closure, SilverStripe\Core\Startup\ErrorControlChain)
ErrorControlChain.php:236

SilverStripe\Core\Startup\ErrorControlChain->step()
ErrorControlChain.php:226

SilverStripe\Core\Startup\ErrorControlChain->execute()
ErrorControlChainMiddleware.php:69

SilverStripe\Core\Startup\ErrorControlChainMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62

SilverStripe\Control\HTTPApplication->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
HTTPMiddlewareAware.php:65

SilverStripe\Control\HTTPApplication->callMiddleware(SilverStripe\Control\HTTPRequest, Closure)
HTTPApplication.php:67

SilverStripe\Control\HTTPApplication->execute(SilverStripe\Control\HTTPRequest, Closure, )
HTTPApplication.php:49

SilverStripe\Control\HTTPApplication->handle(SilverStripe\Control\HTTPRequest)
index.php:17
maxime-rainville commented 6 years ago

Thanks for taking the time to report this issue.

I had a go at replicating it, but didn't manage to. I got intervention to throw a warning in my face, but I had to hack the library to remove the error suppression on $data = @exif_read_data($image->dirname .'/'. $image->basename);

Could you give us more information about what version of EXIF you are running. What does your phpinfo(); printout say about it? FYI that's what I get.

image

Could you let us know exactly which version of intervention your are running? You can use composer to find out composer show intervention/image.

Any chance you could attach a copy of the exact image that is causing the error?

michalkleiner commented 6 years ago

Hi, thanks for the prompt reaction.

name     : intervention/image
descrip. : Image handling and manipulation library with support for Laravel integration
keywords : gd, image, imagick, laravel, thumbnail, watermark
versions : * 2.4.1
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
source   : [git] https://github.com/Intervention/image.git 3603dbcc9a17d307533473246a6c58c31cf17919
dist     : [zip] https://api.github.com/repos/Intervention/image/zipball/3603dbcc9a17d307533473246a6c58c31cf17919 3603dbcc9a17d307533473246a6c58c31cf17919
names    : intervention/image

autoload
psr-4
Intervention\Image\ => src/Intervention/Image

requires
ext-fileinfo *
guzzlehttp/psr7 ~1.1
php >=5.4.0

requires (dev)
mockery/mockery ~0.9.2
phpunit/phpunit ^4.8 || ^5.7

suggests
ext-gd to use GD library based image processing.
ext-imagick to use Imagick based image processing.
intervention/imagecache Caching extension for the Intervention Image library

screen shot 2018-06-14 at 1 46 39 pm

As an example, any PNG I tried did the same. This is the smallest I tested with: announcement

michalkleiner commented 6 years ago

Also the https://secure.php.net/manual/en/book.scream.php is not installed.

kinglozzer commented 6 years ago

Looks like PHP is supposed to emit warnings if it can’t read the file (https://github.com/php/php-src/blob/1ccada35c08d35d87706c8c58cc72eebc80b718b/ext/exif/tests/bug62523_3.phpt). That doesn’t answer why:

  1. A warning is being converted to an exception
  2. PHP is ignoring the error suppression operator

I’ve seen PHP ignore @ before, so it’s possible that it’s a PHP bug. Comparing the two PHP versions above, nothing leaps out at me :/ https://github.com/php/php-src/compare/php-7.1.16...php-7.1.18

michalkleiner commented 6 years ago

Sorry everyone, false alarm - there is a custom error handler used which actually turns everything into an exception :-/ Appreciate your time spent on this issue!

maxime-rainville commented 6 years ago

All good!