SixLabors / ImageSharp

:camera: A modern, cross-platform, 2D Graphics library for .NET
https://sixlabors.com/products/imagesharp/
Other
7.34k stars 847 forks source link

Application crashes when trying to mutate an image #2604

Closed DigitalEntry closed 8 months ago

DigitalEntry commented 9 months ago

Prerequisites

ImageSharp version

4.0.0-alpha.0.1

Other ImageSharp packages and versions

ImageSharp.Drawing 2.0.2-alpha.0.1

Environment (Operating system, version and so on)

Windows 11

.NET Framework version

8.0

Description

The application just crashes when trying to mutate an image. I have tried multiple images and have gotten the same error. I have tried on versions 1.0.4, 2.1.6, 3.1.0 and now 4.0.0 with all of them doing the same thing. I was able to make a few dumps of the program and got these 2 errors

ERROR_CODE: (NTSTATUS) 0xc0000409 - The system detected an overrun of a stack-based buffer in this application. This overrun could potentially allow a malicious user to gain control of this application.

ERROR_CODE: (NTSTATUS) 0xc0000374 - A heap has been corrupted.

Steps to Reproduce

I do not know how I would reproduce it since it doesn't happen all the time, Most of the time when trying to mutate an image the program just shuts down but then others it will work fine.

Images

0b1d89f2474e6dac46d1b02baa06150b

JimBobSquarePants commented 9 months ago

We’re going to need a lot more information please.

I would recommend creating and sharing a program that replicates the issue.

As a side note.

ImageSharp.Drawing 2.0.1 is not binary compatible with ImageSharp 4-alpha, you should use latest stable 2.1.0 with 3.1.0

You are incorrectly declaring the first drawing action as async.

Creating the same font 3 times is inefficient.

JimBobSquarePants commented 8 months ago

@DigitalEntry Do you have this additional information? Otherwise, we will have to close this issue.

DigitalEntry commented 8 months ago

Not at this time. I created another program to try to reproduce the error using the same code in the original program and it worked fine. I'll have to look into it more to see if I can find what's creating this error

DigitalEntry commented 8 months ago

@JimBobSquarePants So I did end up fixing the issue, I don't know what was wrong but I figured since I only changed a few things and it stopped working I could maybe try retracing my steps and see if anything I changed somehow made it stop working. I implemented a MemoryCache to cache users a little while back so I switched from MemoryCache to LazyCache just to see what would happen and that fixed my problem. I don't know how but it works fine now.

JimBobSquarePants commented 8 months ago

Hmmm... I wonder whether buffers in your cache were being disposed of prematurely in your application. I'll close this just now but if you have further problems don't hesitate to open a new issue.