Make WordPress Core

Opened 12 years ago

Last modified 9 months ago

#23127 new defect (bug)

Media Upload hangs on Crunching on too big image sizes.

Reported by: clubdesign's profile clubdesign Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.7
Component: Media Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

If the uploaded file is too big for the Max Memory Limit Setting, then the upload is executed, but the image isn't resized to the set image sizes and the frontend gets stuck on "Crunching". I tracked the error down into the core and found out, that the main problem is in the GD library class ( wp-includes/class-wp-image-editor-gd.php ) in the load() function.

Everything works fine before line 91:

$this->image = @imagecreatefromstring( file_get_contents( $this->file ) );

So imagecreatefromstring fails because of a lack of memory. But as a chain reaction everything else fails afterwards. The library is not loaded and sent back, and so on. As a result no id is sent back to the frontend and the Loader hangs.

Maybe there should be any error catching and sending back before this GD function, that the frontend receives any error messages and that the upload is deleted in case of error.

Just my thoughts: As this error is a Fatal one, you can`t use any Exception stuff, cause there will not be any memory left to execute it. Maybe some checking if the id is present before sending the image back to crunching?

Attachments (2)

23127.patch (4.4 KB) - added by gmariani405 7 years ago.
Returns error message on fatal error, displays error message on fatal error if applicable
test.jpg (1.7 MB) - added by gmariani405 7 years ago.
Sample file to exhaust 256M of memory

Download all attachments as: .zip

Change History (30)

#1 follow-up: @clubdesign
12 years ago

Another thought on how to prevent this thing from hanging, is to do some basic calculations before to any GD Stuff.

As this article explains there is a rough formula for that:
Width x Height x 8 (bits) x 3(channels) / 8 x 1.65
should result in the memory needed for GD. Soooo: Max availiable Memory - Wp needed memory - calc. needed memory. If negative, kick error. Just as a thought. ;)

#2 @SergeyBiryukov
12 years ago

  • Description modified (diff)

#3 @SergeyBiryukov
12 years ago

  • Description modified (diff)

#4 @SergeyBiryukov
12 years ago

  • Component changed from Upload to Media

#6 @SergeyBiryukov
11 years ago

#24703 was marked as a duplicate.

#7 in reply to: ↑ 1 @kb_unhammer
11 years ago

Replying to clubdesign:

Another thought on how to prevent this thing from hanging, is to do some basic calculations before to any GD Stuff.

As this article explains there is a rough formula for that:
Width x Height x 8 (bits) x 3(channels) / 8 x 1.65
should result in the memory needed for GD. Soooo: Max availiable Memory - Wp needed memory - calc. needed memory. If negative, kick error. Just as a thought. ;)

As mentioned in #24703, it would also be nice if whatever error message is shown to the user mentions the php.ini memory_limit workaround.

#8 @SergeyBiryukov
11 years ago

#22870 was marked as a duplicate.

#9 @helen
11 years ago

#8754 was marked as a duplicate.

#10 @helen
11 years ago

#7491 was marked as a duplicate.

#11 @helen
11 years ago

#12532 was marked as a duplicate.

#12 @helen
11 years ago

  • Version changed from 3.5 to 2.7

Apparently this is an ages old problem - some older tickets had already been closed, so I left them alone but marked as duplicates.

#13 @markoheijnen
11 years ago

  • Milestone changed from Awaiting Review to 3.7

Moving to 3.7. I will give it a spin this weekend.

#14 @helen
11 years ago

  • Milestone changed from 3.7 to Awaiting Review

No spin, punt.

#15 @helen
11 years ago

#25490 was marked as a duplicate.

#16 @SergeyBiryukov
11 years ago

#27004 was marked as a duplicate.

#17 @SergeyBiryukov
9 years ago

#31879 was marked as a duplicate.

#18 @SergeyBiryukov
9 years ago

#31940 was marked as a duplicate.

#19 @SergeyBiryukov
7 years ago

#41483 was marked as a duplicate.

@gmariani405
7 years ago

Returns error message on fatal error, displays error message on fatal error if applicable

#20 @gmariani405
7 years ago

Uploaded my first real patch, so please let me know if i did not follow protocol or standards, etc. I have code to safely return an error message in the event of a fatal error in this scenario. Also at the suggestion clubdesign, I have it estimating if it will fail and returning an wp_error. The only issue in this case is that I can't (haven't really dug into) get it to return a memory exhausted type error. Instead it just shows "An error occurred in the upload. Please try again later." which is atleast something. If the memory estimating is too unreliable, the fatal handler shows the appropriate memory error. I've also attached a sample image that will 9 times out of 10 cause a memory exhaust error for a limit of 256M. Again, any feedback is appreciated.

@gmariani405
7 years ago

Sample file to exhaust 256M of memory

#21 @spacedmonkey
5 years ago

I think we should focus the rest api and this ticket #40410

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


4 years ago

#23 @johnbillion
4 years ago

  • Keywords has-patch needs-refresh added

#24 @antpb
4 years ago

  • Keywords has-patch needs-refresh removed
  • Milestone changed from Awaiting Review to 5.8

After many years it seems that this might be ready given the context of modern php and the approach in the patch being solid.

Moving this into 5.8 so we can keep an eye on it and target getting it refreshed and merged by then.

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


3 years ago

#26 @antpb
3 years ago

In a recent Media meeting this issue was brought up and it was asked by @joyously "This is old. Wasn't this addressed fairly recently by the error processing added for image uploads?"

I think we'll need to investigate if that error handling covers this case. If not, refresh still pending and I'll get that diff uploaded very soon!

Last edited 3 years ago by antpb (previous) (diff)

#27 @desrosj
3 years ago

  • Milestone changed from 5.8 to Future Release

Today is the beta 1 deadline for 5.8. I am going to punt this one to Future Release, as there is still testing and investigation to be performed.

#28 @imanish003
9 months ago

We are facing a similar issue https://github.com/woocommerce/woocommerce/issues/30379 on WooCommerce. Could you please share any updates or planned timelines for addressing this? Thank you 🙏🏻

Note: See TracTickets for help on using tickets.