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

Image Crop on one Gif results in out of memory errory #2848

Open
4 tasks done
RachBreeze opened this issue Dec 16, 2024 · 6 comments
Open
4 tasks done

Image Crop on one Gif results in out of memory errory #2848

RachBreeze opened this issue Dec 16, 2024 · 6 comments

Comments

@RachBreeze
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

3.1.6

Other ImageSharp packages and versions

SixLabors.ImageSharp.Web 3.1.3.0 SixLabors.ImageSharp.Web.Providers.Azure 3.1.3.0

Environment (Operating system, version and so on)

Microsoft Azure Web App

.NET Framework version

.net 8

Description

Hello

We have a file that causes an OOM Exception when cropped.

The file is here https://github.com/RachBreeze/ImageSharp.Payloads/blob/main/blob/bluebeam.gif

The crop that causes the issue is width width=850 and height=459.23379174852647

The site is hosted on Azure Web App P0V3

Thank you in advance for all your help

Steps to Reproduce

The image is in an Umbraco 13.5.2 site and is loaded into the website via bluebeam.gif?width=850&height=459.23379174852647

Images

No response

@JimBobSquarePants
Copy link
Member

Hmmm.... This is a BIG gif and I don't think there's much I can do.

The problem here is that we have to allocate enough memory for both the source and target image since crop requires a clone to be created.

Source

(2545 x 1375 x 100 x 4 bytes) / 1024 / 1024 = 1.334GB

Destination

(850 x 460 x 100 x 4 bytes) / 1024 / 1024 = 149MB

Azure POV3 has a maximum of 4GB memory available and I've no idea how what resources the application takes and how much traffic there is but I imagine it's probably a struggle to maintain that much available memory for an individual operation.

@antonfirsov
Copy link
Member

antonfirsov commented Dec 16, 2024

@RachBreeze can you share the exception info including the stack trace?

@RachBreeze
Copy link
Author

Thank you both for your quick response

@JimBobSquarePants that's a great spot let me see if we can do some file size reduction at our end, I will keep your posted.

If we can't @antonfirsov I will defiantly include the exception info for you

@antonfirsov
Copy link
Member

antonfirsov commented Dec 16, 2024

@RachBreeze the reason I asked is that if it's a system OOM, there is a way to configure a memory limit for the library, so you will get an InvalidMemoryOperationException instead of an OOM, which will be thrown before starting the decoding operation. This would give you an opportunity to handle such images as exceptional cases in a catch block. If your app runs in a memory-limited environment, and your inputs are not trusted, you may want to apply a lower-than-default limit for security reasons too.

See details here: https://docs.sixlabors.com/articles/imagesharp/security.html

@RachBreeze
Copy link
Author

Hi @JimBobSquarePants and @antonfirsov

I didn't capture the error message other than it was Out Of memory, please forgive me.

Just to flag that this file https://github.com/RachBreeze/ImageSharp.Payloads/blob/main/blob/bluebeam.gif is 13.5 mb not gb.

I also have it eating memory locally on a 32 GB machine (31.7GB usable) . The specs are:

  • 12th Gen Intel(R) Core(TM) i9-12900HK
  • 2.50 GHz , 64-bit operating system, x64-based processor
    With the following OS
  • Windows 11 Pro
  • Windows Feature Experience Pack 1000.22700.1055.0

@antonfirsov
Copy link
Member

antonfirsov commented Dec 17, 2024

Just to flag that this file [..] is 13.5 mb not gb.

That's the size of the compressed gif file. When you unpack it into an in-memory Image object, all frames will be represented as uncompressed pixel buffers internally, and as #2848 (comment) mentions this means that 100 frames. This is by design/by architecture in current ImageSharp versions.

Where do such images come from? Is it uplodaded by users? Is filtering out such inputs (eg. at upload time) an option?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants