roundcube / roundcubemail

The Roundcube Webmail suite
https://roundcube.net
GNU General Public License v3.0
5.9k stars 1.64k forks source link

inline_images option causes memory exhaustion on large attachments #6718

Closed agittins closed 5 years ago

agittins commented 5 years ago

Using roundcube 1.3.4 in a docker container as part of jeboehm's implementation of ispmail.

If I enable the inline_images option (in settings, perferences, displaying images, "Display attached images below the message") then when viewing some emails with multiple (3 or more, say) large (1.2MB plus) jpegs attached, the php-fpm process on the server blows out in memory usage - I saw it get to about 380MB before my server wedged, until oom-killer stepped in.

I found some other bugreports that seemed somewhat related but most seemed to deal with the sending side of things.

When I de-select the inline_images option the emails display fine, and the attachment viewer window works fine. Obviously that's a suitable workaround, but it would be nice to be able to display the images inline if possible.

I note that the inline_images option I think is off by default, so this is "my own fault" for turning it on :-) Near as I can tell RC is trying to scale the images to display them inline, and the memory use is perhaps related to that (GD?). If it results in lower server load, I'd be happy for it to just be sending the full-size image to my browser and letting it handle resizing (perhaps setting width/height attributes on the img tag) rather than putting that burden on the server. That wouldn't suit everyone, I guess, but whether it's a 100kb jpeg or an 80MB TIFF file, I'd rather the server just serve it and not try to pre-process a thumbnail or preview size image.

Is this a security vulnerability as well, since a malicious user could send themselves a huge image and display it inline, exhausting server memory?

Am I missing something else here that solves it, or is this just a tradeoff between user convenience and server load?

TL/DR: Perhaps make the option "Display attached images below the message" not re-scale the images (just serve them at full-size), and have an option under that for "Resize images for inline display (Warning: may result in higher server memory use)" or similar, default to off. Actually that option might be a global config rather than a user setting.

alecpl commented 5 years ago

You're right that this is most likely caused by the thumbnail generation code. There are some things to consider:

TL/DR ;) we can consider making image_thumbnail_size=0 a special setting to disable resizing.

alecpl commented 5 years ago

Actually image_thumbnail_size=0 case is already implemented. It will disable resizing. As I see no feedback on the hints I provided, I'm closing the ticket.