question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AccessViolationException when cloning MagickImage created from corrupt TIFF

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dlemstracommented, Feb 18, 2022

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.

0reactions
dlemstracommented, Feb 19, 2022

Decided that we will always raise an exception in ImageMagick when none was raised by the tiff library.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found