-
-
Notifications
You must be signed in to change notification settings - Fork 886
Closed
Labels
Description
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
DEBUGandRELEASEmode - I have searched open and closed issues to ensure it has not already been reported
ImageSharp version
3.1.5
Other ImageSharp packages and versions
none
Environment (Operating system, version and so on)
Windows 11 23H2 22631.3880
.NET Framework version
.NET SDK 8.0
Description
This happens when using WrapMemory<TPixel>(void* pointer, int bufferSizeInBytes, int width, int height) and passing buffer that is too small for given width, height and TPixel even with correct bufferSizeInBytes value
Expected behaviour
Exception saying that given buffer is too small for given image size and pixel format
Actual behaviour
Fatal error. Internal CLR error
Steps to Reproduce
Run this code
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System.Runtime.InteropServices;
unsafe
{
// these two lines are correct: no overflow ("checked") and no overrun ("bufferSize" is used)
int bufferSize = checked(8192 * 8192);
void* data = NativeMemory.Alloc(checked((nuint)bufferSize));
// passing correct buffer size
using Image<Rgba64> img = Image.WrapMemory<Rgba64>(data, bufferSize, 8192, 8192);
// oops!
img.SaveAsPng("output.png");
// already crashed at this point
NativeMemory.Free(data);
}Images
No response