AccessViolationException when cloning MagickImage created from corrupt TIFF
See original GitHub issueDescription
Trying to Clone
a MagickImage
instance that has been created by loading the attached corrupt.tif file results in an AccessViolationException
:
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.MagickImage+NativeMethods+X64.MagickImage_Clone(IntPtr, IntPtr ByRef)
--------------------------------
at ImageMagick.MagickImage+NativeMagickImage.Clone()
at ImageMagick.MagickImage..ctor(ImageMagick.IMagickImage`1<Byte>)
at ImageMagick.MagickImage.Clone()
at Magick.NET.Samples.Program.Main()
Steps to Reproduce
Compile and run the following .NET 5 application:
using ImageMagick;
namespace Magick.NET.Samples
{
class Program
{
static void Main()
{
using (var image = new MagickImage("corrupt.tif"))
{
image.Clone();
}
}
}
}
System Configuration
- Magick.NET version: Magick.NET-Q8-x64 9.1.2 (and current master branch)
- Environment (Operating system, version and so on): Windows 10
Additional Information
Magick++ behavior
The roughly equivalent Magick++ version of the repro program raises an exception when reading the image:
#include <Magick++.h>
#include <iostream>
using namespace std;
using namespace Magick;
int main(int argc, char **argv)
{
InitializeMagick(*argv);
try
{
Image image;
image.read("corrupt.tif");
Image clone(image);
}
catch (Exception& error)
{
cout << "Error: " << error.what() << endl;
}
}
Output:
Error: Repro.exe: No image was loaded.
MagickCore behavior
The MagickCore ReadImage
function returns NULL
for this file, but sets no ExceptionInfo
. I’m not sure if that is something that is allowed to happen, but it does for this file.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
System.AccessViolationException: Attempted to read or ...
AccessViolationException: Attempted to read or write protected ... This is often an indication that other memory is corrupt. at ImageMagick.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for reporting this. I can also reproduce this issue without the image. The
Clone
method seems to be missing a null check. This will be fixed in the next release.Decided that we will always raise an exception in ImageMagick when none was raised by the tiff library.