craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.22k stars 626 forks source link

[4.x]: Image dimensions null when expected memory usage exceeds the limit #13687

Closed jeroenverfallie closed 10 months ago

jeroenverfallie commented 1 year ago

What happened?

Description

Given an image with a large dimension (for example 8000x9500) the Raster->loadImage() method returns a memory exception. This causes the image to exists in the database with a width & height being null.

https://github.com/craftcms/cms/blob/develop/src/image/Raster.php#L163-L166

Expected behavior

Even if craft is unable to produce the cp image transforms, we'd expect the dimensions of the original image to be available, as loading these is a low-cost operation. In fact, the method used to calculate the expected memory usage (getimagesize()) offers the dimensions by itself.

Craft CMS version

4.4.17

PHP version

8.1

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

i-just commented 1 year ago

Hi, thanks for reaching out.

Could you please confirm your image driver and post the error from your logs?

I was able to replicate this behaviour when using imagick (gd seems to handle the same large images well), though not caused by the lines you linked to.

The error I ran into was internal to ImageMagick. I made some changes to improve logging around what’s happening, and we’ll also have an internal discussion about this.

stijntilleman commented 11 months ago

Hi @i-just,

we've added the extra logging mentioned in pr https://github.com/craftcms/cms/pull/13694 to the project @jeroenverfallie mentioned above.

When using the imagick driver we get an extra log entry but the image is uploaded to the website

2023-09-26 14:29:21 [web.WARNING] [craft\helpers\Image::imageSize] Not enough memory available to perform this image operation. {"memory":6769504} 

When we switched to the gd driver


Completing the information provided by jeroen

Operating system and version

ubuntu 18.04.6

Database type and version

MySQL 5.7.42

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.7-4)

Installed plugins and versions

Name Handle Package Name Version Installed Enabled
Amazon S3 aws-s3 craftcms/aws-s3 2.0.3 Yes Yes
Content Sync contentsync bitsoflove/contentsync-plugin 0.0.1 Yes Yes
Control Panel CSS cp-css doublesecretagency/craft-cpcss 2.6.0 Yes Yes
Control Panel Nav cp-nav verbb/cp-nav 4.0.10 Yes Yes
CP Field Inspect cp-field-inspect mmikkel/cp-field-inspect 1.4.4 Yes Yes
Craft Report craft-reporter webmenedzser/craft-reporter 2.1.3 Yes Yes
Dashboard Begone dashboard-begone putyourlightson/craft-dashboard-begone 2.0.0 Yes Yes
Embed Code embedcode bitsoflove/embedcode-plugin 1.0.0 Yes Yes
Environment Label environment-label topshelfcraft/environment-label 4.0.3 Yes Yes
External Relations external-relations bitsoflove/external-relations 0.0.1 Yes Yes
Feed Me feed-me craftcms/feed-me 5.2.0 Yes Yes
Field Labels fieldlabels bitsoflove/craftcms-field-labels 0.0.1 Yes Yes
Field Manager field-manager verbb/field-manager 3.0.6 Yes Yes
Jason jason chasegiunta/craft-jason 3.0.1 Yes Yes
LJ Default Text craft-default-text lewisjenkins/craft-default-text 4.0.1 Yes Yes
Matches matches bitsoflove/matches-plugin 0.0.1 Yes Yes
Navigation navigation verbb/navigation 2.0.18 Yes Yes
Neo neo spicyweb/craft-neo 3.8.0 Yes Yes
Notifications notifications bitsoflove/notifications-plugin 0.0.1 Yes Yes
Page Builder pagebuilder bitsoflove/pagebuilder-plugin 0.0.1 Yes Yes
Read Only read-only codewithkyle/read-only 1.0.5 Yes Yes
Redactor redactor craftcms/redactor 3.0.4 Yes Yes
Retour retour nystudio107/craft-retour 4.1.12 Yes Yes
Super Table super-table verbb/super-table 3.0.9 Yes Yes
Twigpack twigpack nystudio107/craft-twigpack 4.0.0-beta.4 Yes Yes
User Manual usermanual roberskine/craft-user-manual 4.0.0 Yes Yes
Webhooks webhooks craftcms/webhooks 3.0.4 Yes Yes
Neo Template neo-template bitsoflove/craftcms-neo-template 0.0.1 Yes No
i-just commented 10 months ago

@jeroenverfallie we added a fallback to use getimagesize to get image dimensions.

brandonkelly commented 10 months ago

Craft 4.5.10 is out now, with the getimagesize() fallback.