Magick.net: MagickImage does not respect MemoryStream internal buffer origin

Created on 22 Oct 2020  路  2Comments  路  Source: dlemstra/Magick.NET

Description

MagickImage should not rely on the GetBuffer method of the MemoryStream, but should call TryGetBuffer and respect the Offset property.

Steps to Reproduce

byte[] data = File.ReadAllBytes("E:\\Temp\\image.jpg"); // any image.
byte[] testBuffer = new byte[data.Length + 10];
data.CopyTo(testBuffer, index: 10); // copying entire image to the buffer skipping first 10 bytes.

// tell the stream to skip the first 10 bytes.
var stream = new MemoryStream(testBuffer, 
index: 10, 
count: testBuffer.Length - 10, 
writable: false, 
publiclyVisible: true); // <- here is the problem. Works when false.

// throws MagickMissingDelegateErrorException: no decode delegate for this image format.
MagickImage image = new MagickImage(stream);

System Configuration

  • Magick.NET version: Magick.NET-Q16-AnyCPU 7.22.0
  • Environment (Operating system, version and so on): Windows 10 x64
bug

All 2 comments

Thanks for reporting this. It seems that TryGetBuffer is only available for .NET standard. I took a look at the source code of MemoryStream but for .NET framework there is no real solution for this. And because this is an edge case it should be okay for those older versions. The patch will be applied for .NET standard though.

A new release of Magick.NET that resolves this issue has been published.

Was this page helpful?
0 / 5 - 0 ratings