Magick.NET icon indicating copy to clipboard operation
Magick.NET copied to clipboard

Pinging some EXR files results in fatal System.AccessViolationException

Open TobiasWolters opened this issue 1 year ago • 4 comments

Magick.NET version

Magick.NET.Core, Version ^13.9.1

Environment (Operating system, version and so on)

Windows 11 Pro, 23H2

Description

When pinging the exr file that can be found in this zip, the process crashes with the following exception:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
   at ImageMagick.MagickImageCollection+NativeMethods+X64.MagickImageCollection_ReadStream(IntPtr, ReadWriteStreamDelegate, SeekStreamDelegate, TellStreamDelegate, Void*, IntPtr ByRef)
--------------------------------
   at ImageMagick.MagickImageCollection+NativeMagickImageCollection.ReadStream(ImageMagick.IMagickSettings`1<Single>, ReadWriteStreamDelegate, SeekStreamDelegate, TellStreamDelegate, Void*)
   at ImageMagick.MagickImageCollection+NativeMagickImageCollection.ReadStream(ImageMagick.IMagickSettings`1<Single>, ReadWriteStreamDelegate, SeekStreamDelegate, TellStreamDelegate)
   at ImageMagick.MagickImageCollection.AddImages(System.IO.Stream, ImageMagick.IMagickReadSettings`1<Single>, Boolean)
   at ImageMagick.MagickImageCollection.Ping(System.IO.Stream, ImageMagick.IMagickReadSettings`1<Single>)
...

The issue should be reproducible by doing something along the lines of:

<read-exr-file-as-stream>
using var magickImageCollection = new MagickImageCollection();
magickImageCollection.Ping(exrStream, null);

I have tested that this also is an issue in 13.10.0 and 14.0.0

This works in version 13.6.0.

Steps to Reproduce

See the description above.

TobiasWolters avatar Oct 11 '24 10:10 TobiasWolters

Thanks for reporting this. It turns out ImageMagick cannot read these images because we only support scanline images. But there is a bug in the part of the code that reports the error. I just pushed a patch to the ImageMagick repository to fix this. This bug will be fixed in the next release.

dlemstra avatar Oct 12 '24 10:10 dlemstra

@dlemstra Thanks! Out of curiosity: If ImageMagick can not read these image, then how come that it works in Magick.NET.Core 13.6.0?

TobiasWolters avatar Oct 14 '24 05:10 TobiasWolters

There might have been changes in the exr api or how we are using it. I will need to investigate that but I don't know when I will make time for that.

dlemstra avatar Oct 14 '24 11:10 dlemstra

I had some time tonight and I was able to restore support for reading tiled images with the new api of openexr that is used by ImageMagick. In the next release you will be able to read this image again.

dlemstra avatar Oct 15 '24 20:10 dlemstra