Skip to content

Resizing WebP MagickImage disposes it #2076

Description

@reima

Magick.NET version

Magick.NET-Q8-AnyCPU 14.16.0

Environment (Operating system, version and so on)

Windows 11

Description

Loading the attached WebP image as a MagickImage works without an error. Resizing the image also seems to work, but unexpectedly disposes the MagickImage.

Note: I recognize that the WebP is corrupt (it is a partially restored deleted file). However my expectation would be that Magick.NET either throws an exception when loading the image or allows resizing the image without disposing it.

Steps to Reproduce

Run this code in a .NET 10 project:

using ImageMagick;
using System;

try
{
    using var image = new MagickImage("repro.webp");
    image.Resize(50, 50);
    Console.WriteLine($"Success ({image.Width} x {image.Height})");
}
catch (Exception ex)
{
    Console.WriteLine($"Failed: {ex}");
}

Observe that an ObjectDisposedException is thrown when accessing image.Width in line 8:

Failed: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'MagickImage'.
   at ImageMagick.NativeInstance.get_Instance() in /_/src/Magick.NET/Native/NativeInstance.cs:line 20
   at ImageMagick.MagickImage.NativeMagickImage.Width_Get() in /_/src/Magick.NET/Generated/Magick.NET.SourceGenerator/ImageMagick.SourceGenerator.NativeInteropGenerator/MagickImage.g.cs:line 5053
   at ImageMagick.MagickImage.get_Width() in /_/src/Magick.NET/MagickImage.cs:line 834
   at Program.<Main>$(String[] args) in F:\Source\.local\Magick.NET\MagickTest\Program.cs:line 8

Images

repro.webp

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions