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

EXIF tool addition breaks importing PNG and GIFs #413

Closed
alex-phillips opened this issue Dec 24, 2019 · 25 comments · Fixed by LycheeOrg/php-exif#7
Closed

EXIF tool addition breaks importing PNG and GIFs #413

alex-phillips opened this issue Dec 24, 2019 · 25 comments · Fixed by LycheeOrg/php-exif#7
Assignees
Labels
bug Something isn't working High Priority High priority issues

Comments

@alex-phillips
Copy link
Contributor

Detailed description of the problem

Unless I'm missing a package (I've installed php-exif and exiftool), I'm now getting a 500 error when importing PNG or GIF files. I've tried both with has_exiftool = 0 and = 1.

Error when has_exiftool=0:

(1/1) Error  Call to a member function getMimeType() on bool
--
in Extractor.php line 87
at Extractor->extract('/app/lychee/public/uploads/big/b38c37a22a3dea48ba0f556f1052c568.gif', 'image/gif')in PhotoFunctions.php line 331
at PhotoFunctions->add(array('name' => 'XMHK3LQ.gif', 'type' => 'image/gif', 'tmp_name' => '/tmp/phpneoMff'), '0')in PhotoController.php line 173
at PhotoController->add(object(Request))
at call_user_func_array(array(object(PhotoController), 'add'), array(object(Request)))in Controller.php line 54
at Controller->callAction('add', array(object(Request)))in ControllerDispatcher.php line 45
at ControllerDispatcher->dispatch(object(Route), object(PhotoController), 'add')in Route.php line 219
at Route->runController()in Route.php line 176
at Route->run()in Router.php line 681
at Router->Illuminate\Routing\{closure}(object(Request))in Pipeline.php line 130
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in UploadCheck.php line 54
at UploadCheck->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in VerifyCsrfToken.php line 76
at VerifyCsrfToken->handle(object(Request), object(Closure))in VerifyCsrfToken.php line 60
at VerifyCsrfToken->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in AuthenticateSession.php line 39
at AuthenticateSession->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in StartSession.php line 56
at StartSession->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in EncryptCookies.php line 66
at EncryptCookies->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 105
at Pipeline->then(object(Closure))in Router.php line 683
at Router->runRouteWithinStack(object(Route), object(Request))in Router.php line 658
at Router->runRoute(object(Request), object(Route))in Router.php line 624
at Router->dispatchToRoute(object(Request))in Router.php line 613
at Router->dispatch(object(Request))in Kernel.php line 177
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))in Pipeline.php line 130
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in SecureHeadersMiddleware.php line 21
at SecureHeadersMiddleware->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in TrustProxies.php line 57
at TrustProxies->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in TransformsRequest.php line 21
at TransformsRequest->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in TransformsRequest.php line 21
at TransformsRequest->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in ValidatePostSize.php line 27
at ValidatePostSize->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in CheckForMaintenanceMode.php line 62
at CheckForMaintenanceMode->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 105
at Pipeline->then(object(Closure))in Kernel.php line 152
at Kernel->sendRequestThroughRouter(object(Request))in Kernel.php line 117
at Kernel->handle(object(Request))in index.php line 53

Error when has_exiftool=1

(1/1) ErrorException  Undefined offset: 1
--
in Exiftool.php line 297
at HandleExceptions->handleError(8, 'Undefined offset: 1', '/app/lychee/vendor/lychee-org/php-exif/lib/PHPExif/Mapper/Exiftool.php', 297, array('data' => array('SourceFile'  =>  '/app/lychee/public/uploads/big/88882e7b0d64d1af3ada61c2afd9f3ca.gif',  'ExifTool:ExifToolVersion' => 11.79, 'System:FileName' =>  '88882e7b0d64d1af3ada61c2afd9f3ca.gif', 'System:Directory' =>  '/app/lychee/public/uploads/big', 'System:FileSize' => 544227,  'System:FileModifyDate' => '2019:12:24 18:22:37+00:00',  'System:FileAccessDate' => '2019:12:24 18:22:37+00:00',  'System:FileInodeChangeDate' => '2019:12:24 18:22:37+00:00',  'System:FilePermissions' => 644, 'File:FileType' => 'GIF',  'File:FileTypeExtension' => 'GIF', 'File:MIMEType' => 'image/gif',  'GIF:GIFVersion' => '89a', 'GIF:ImageWidth' => 500,  'GIF:ImageHeight' => 340, 'GIF:HasColorMap' => 1,  'GIF:ColorResolutionDepth' => 8, 'GIF:BitsPerPixel' => 6,  'GIF:BackgroundColor' => 0, 'GIF:AnimationIterations' => 0,  'GIF:FrameCount' => 42, 'GIF:Duration' => 3.78,  'Composite:ImageSize' => '500 340', 'Composite:Megapixels' =>  0.17), 'mappedData' => array('FileName' =>  '88882e7b0d64d1af3ada61c2afd9f3ca.gif', 'FileSize' => 544227,  'MimeType' => 'image/gif', 'width' => 500), 'gpsData' => array(), 'value' => '500 340', 'field' => 'Composite:ImageSize', 'key' => 'width', 'value_splitted' => array('500 340'), 'rotate' => false))in Exiftool.php line 297
at Exiftool->mapRawData(array('SourceFile'  =>  '/app/lychee/public/uploads/big/88882e7b0d64d1af3ada61c2afd9f3ca.gif',  'ExifTool:ExifToolVersion' => 11.79, 'System:FileName' =>  '88882e7b0d64d1af3ada61c2afd9f3ca.gif', 'System:Directory' =>  '/app/lychee/public/uploads/big', 'System:FileSize' => 544227,  'System:FileModifyDate' => '2019:12:24 18:22:37+00:00',  'System:FileAccessDate' => '2019:12:24 18:22:37+00:00',  'System:FileInodeChangeDate' => '2019:12:24 18:22:37+00:00',  'System:FilePermissions' => 644, 'File:FileType' => 'GIF',  'File:FileTypeExtension' => 'GIF', 'File:MIMEType' => 'image/gif',  'GIF:GIFVersion' => '89a', 'GIF:ImageWidth' => 500,  'GIF:ImageHeight' => 340, 'GIF:HasColorMap' => 1,  'GIF:ColorResolutionDepth' => 8, 'GIF:BitsPerPixel' => 6,  'GIF:BackgroundColor' => 0, 'GIF:AnimationIterations' => 0,  'GIF:FrameCount' => 42, 'GIF:Duration' => 3.78,  'Composite:ImageSize' => '500 340', 'Composite:Megapixels' =>  0.17))in Exiftool.php line 159
at Exiftool->getExifFromFile('/app/lychee/public/uploads/big/88882e7b0d64d1af3ada61c2afd9f3ca.gif')in Reader.php line 103
at Reader->read('/app/lychee/public/uploads/big/88882e7b0d64d1af3ada61c2afd9f3ca.gif')in Extractor.php line 85
at Extractor->extract('/app/lychee/public/uploads/big/88882e7b0d64d1af3ada61c2afd9f3ca.gif', 'image/gif')in PhotoFunctions.php line 331
at PhotoFunctions->add(array('name' => 'XMHK3LQ.gif', 'type' => 'image/gif', 'tmp_name' => '/tmp/phpDIBoLN'), '0')in PhotoController.php line 173
at PhotoController->add(object(Request))
at call_user_func_array(array(object(PhotoController), 'add'), array(object(Request)))in Controller.php line 54
at Controller->callAction('add', array(object(Request)))in ControllerDispatcher.php line 45
at ControllerDispatcher->dispatch(object(Route), object(PhotoController), 'add')in Route.php line 219
at Route->runController()in Route.php line 176
at Route->run()in Router.php line 681
at Router->Illuminate\Routing\{closure}(object(Request))in Pipeline.php line 130
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in UploadCheck.php line 54
at UploadCheck->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in VerifyCsrfToken.php line 76
at VerifyCsrfToken->handle(object(Request), object(Closure))in VerifyCsrfToken.php line 60
at VerifyCsrfToken->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in AuthenticateSession.php line 39
at AuthenticateSession->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in StartSession.php line 56
at StartSession->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in EncryptCookies.php line 66
at EncryptCookies->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 105
at Pipeline->then(object(Closure))in Router.php line 683
at Router->runRouteWithinStack(object(Route), object(Request))in Router.php line 658
at Router->runRoute(object(Request), object(Route))in Router.php line 624
at Router->dispatchToRoute(object(Request))in Router.php line 613
at Router->dispatch(object(Request))in Kernel.php line 177
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))in Pipeline.php line 130
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in SecureHeadersMiddleware.php line 21
at SecureHeadersMiddleware->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in TrustProxies.php line 57
at TrustProxies->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in TransformsRequest.php line 21
at TransformsRequest->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in TransformsRequest.php line 21
at TransformsRequest->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in ValidatePostSize.php line 27
at ValidatePostSize->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in CheckForMaintenanceMode.php line 62
at CheckForMaintenanceMode->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 105
at Pipeline->then(object(Closure))in Kernel.php line 152
at Kernel->sendRequestThroughRouter(object(Request))in Kernel.php line 117
at Kernel->handle(object(Request))in index.php line 53

JPEG images work fine in both cases.

Steps to reproduce the issue

Fresh install of lychee-laravel > upload file > choose PNG or GIF

Output of the diagnostics

    Diagnostics
    -----------
    Info: Latest version of PHP is 7.4
    Warning: Dropbox import not working. dropbox_key is empty.

    System Information
    ------------------
    Lychee-front Version:      3.2.16
    Lychee Version (git):      ce689ab (master) - Data not in Cache
    DB Version:                040000
    System:                    Linux
    PHP Version:               7.3
    MySQL Version:             10.4.11-MariaDB-1:10.4.11+maria~bionic-log
    
    Lychee total space:        62.55 MB
    Upload folder space:       13.00 B
    System total space:        218.57 GB
    System free space:         25.13 GB (11%)
    
    Imagick:                   1
    Imagick Active:            1
    Imagick Version:           1801
    GD Version:                bundled (2.1.0 compatible)

    Config Information
    ------------------
    version:                   040000
    check_for_updates:         0
    sorting_Photos_col:        takestamp
    sorting_Photos_order:      ASC
    sorting_Albums_col:        max_takestamp
    sorting_Albums_order:      ASC
    imagick:                   1
    skip_duplicates:           0
    small_max_width:           0
    small_max_height:          360
    medium_max_width:          1920
    medium_max_height:         1080
    lang:                      en
    layout:                    1
    image_overlay:             1
    image_overlay_type:        desc
    default_license:           none
    compression_quality:       90
    full_photo:                1
    delete_imported:           0
    Mod_Frame:                 1
    Mod_Frame_refresh:         30
    thumb_2x:                  1
    small_2x:                  1
    medium_2x:                 1
    landing_page_enable:       0
    landing_owner:             John Smith
    landing_title:             John Smith
    landing_subtitle:          Cats, Dogs & Humans Photography
    landing_facebook:          https://www.facebook.com/JohnSmith
    landing_flickr:            https://www.flickr.com/JohnSmith
    landing_twitter:           https://www.twitter.com/JohnSmith
    landing_instagram:         https://instagram.com/JohnSmith
    landing_youtube:           https://www.youtube.com/JohnSmith
    landing_background:        dist/cat.jpg
    site_title:                Lychee v4
    site_copyright_enable:     1
    site_copyright_begin:      2019
    site_copyright_end:        2019
    additional_footer_text:    
    display_social_in_gallery: 0
    public_search:             0
    public_recent:             0
    recent_age:                1
    public_starred:            0
    downloadable:              0
    photos_wraparound:         1
    map_display:               0
    zip64:                     1
    map_display_public:        0
    map_provider:              Wikimedia
    force_32bit_ids:           0
    map_include_subalbums:     0
    update_check_every_days:   3
    has_exiftool:              1
    share_button_visible:      0

Browser and system

lychee-laravel master on Linux (alpine)

@alex-phillips
Copy link
Contributor Author

Note: If I do a git checkout f29fa9a9bbab5f374d6a3823ec0d56a47a18fdc5, then GIF and PNGs work just fine.

@ildyria ildyria added bug Something isn't working High Priority High priority issues labels Dec 24, 2019
@ildyria
Copy link
Member

ildyria commented Dec 24, 2019

Hi @alex-phillips thank you for quickly pointing that out. We will try to fix that one quickly.

@tmp-hallenser
Copy link
Contributor

Hi @alex-phillips
could you provide sample files? That would make debugging easier.
Thanks!

@alex-phillips
Copy link
Contributor Author

@tmp-hallenser
Copy link
Contributor

Just created a PR to fix this issue. Please give it a try.

@alex-phillips
Copy link
Contributor Author

@tmp-hallenser Still no - same errors. Tried with has_exiftool as 0 and 1.

@tmp-hallenser
Copy link
Contributor

Did you run composer install or/and composer update?

@ildyria
Copy link
Member

ildyria commented Dec 25, 2019

@tmp-hallenser if the composer part is missing, do you think we should catch this error and place a log line for it ?

@alex-phillips
Copy link
Contributor Author

Running it in docker and did a fresh build, but after I manually ran install / upgrade, then it worked fine. Thanks guys!

@alex-phillips
Copy link
Contributor Author

It looks like a fresh install won't do, an upgrade is necessary. Curious if there's a version that should be bumped in the composer.json file?

@tmp-hallenser
Copy link
Contributor

Thx for the feedback! Once it's merged into master, a fresh install should be fine.

@alex-phillips
Copy link
Contributor Author

I hate to bring this up again, but with latest, setting exiftool to 0 works, but even with php7-exif and exiftool installed, exiftool set to 1 returns a 500 when uploading a PNG.

@tmp-hallenser
Copy link
Contributor

Hm, that's strange. Just tested it on my dev environment and it works for me. Did you try it with a clean installation? Does it happen for all PNGs? Can you provide the console output (esp. the details of the failure)?

@tmp-hallenser tmp-hallenser reopened this Jan 14, 2020
@alex-phillips
Copy link
Contributor Author

@tmp-hallenser Here's a screenshot of the output. I can post more if its needed, but didn't want a giant image if it was unnecessary.

image

@tmp-hallenser
Copy link
Contributor

@alex-phillips The issue is the extraction of the meta data which fails. Can you share a sample file?

@alex-phillips
Copy link
Contributor Author

alex-phillips commented Jan 14, 2020

@tmp-hallenser
Copy link
Contributor

Thanks for the file. That's really strange. The error happens in line 297 which means, the explode(...) statement at the beginning of the case statement ist not working on your system (it does on my system). Can you try the following 2 things for me:

  1. Paste the output of exiftool -G filename.png
  2. Add a line vardump($value); before the line $value_splitted = explode(...) and share this output?

I realized that your file contains a creation date which is not extracted - I'll fix that as well.

@alex-phillips
Copy link
Contributor Author

@tmp-hallenser

exiftool output:

root@c49996ccdddb:/config# exiftool -G screen.png 
[ExifTool]      ExifTool Version Number         : 11.79
[File]          File Name                       : screen.png
[File]          Directory                       : .
[File]          File Size                       : 767 kB
[File]          File Modification Date/Time     : 2020:01:14 14:09:32-05:00
[File]          File Access Date/Time           : 2020:01:14 14:09:32-05:00
[File]          File Inode Change Date/Time     : 2020:01:14 14:09:42-05:00
[File]          File Permissions                : rw-r--r--
[File]          File Type                       : PNG
[File]          File Type Extension             : png
[File]          MIME Type                       : image/png
[PNG]           Image Width                     : 1920
[PNG]           Image Height                    : 1080
[PNG]           Bit Depth                       : 8
[PNG]           Color Type                      : RGB with Alpha
[PNG]           Compression                     : Deflate/Inflate
[PNG]           Filter                          : Adaptive
[PNG]           Interlace                       : Noninterlaced
[PNG]           Significant Bits                : 8 8 8 8
[PNG]           Software                        : gnome-screenshot
[PNG]           Creation Time                   : Thu 09 Jan 2020 09:35:35 PM EST
[Composite]     Image Size                      : 1920x1080
[Composite]     Megapixels                      : 2.1

vardump output:

string(9) "1920 1080" 

@alex-phillips
Copy link
Contributor Author

Looks like you're exploding by 'x', but my OS (for some reason) returns as a space. Perhaps a regex to determine if you should explode by 'x' or by space?

@alex-phillips
Copy link
Contributor Author

if (preg_match('#^\d+x\d+$#', $value)) {
    $value_splitted = explode("x", $value);
} else {
    $value_splitted = explode(" ", $value);
}

@alex-phillips
Copy link
Contributor Author

@tmp-hallenser even better:

preg_match("#^(\d+)[^\d]+(\d+)$#", $value, $matches);
$value_splitted = array_slice($matches, 1);

@alex-phillips
Copy link
Contributor Author

I can open a PR if you want :-P

@tmp-hallenser
Copy link
Contributor

I've just pushed 'fix_413_part_2' to https://github.com/LycheeOrg/php-exif.git

You can give it a try

@tmp-hallenser
Copy link
Contributor

thanks for the drill down

@alex-phillips
Copy link
Contributor Author

Awesome! I was having the same issue with GIFs but this fixes that as well. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working High Priority High priority issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants