Skip to content

Fail to Load a Gif Image with v2.0.0 but works with v1.0.4 on the same machine. #2012

Description

@paulyipkh

ImageSharp version

2.0.0

Other ImageSharp packages and versions

1.0.4

Environment (Operating system, version and so on)

Windows 10

.NET Framework version

.NET 5

Description

I came across a gif image https://www.muhammadniaz.net/wp-content/uploads/2013/06/Stronghold-Crusader-Extreme-Cover.gif which loaded correctly with ImageSharp v1.0.4 but failed with v2.0.0 with an unmanaged exception which cannot be caught by the try-catch

Steps to Reproduce

try
{
    var client = new HttpClient();
    string url = "https://www.muhammadniaz.net/wp-content/uploads/2013/06/Stronghold-Crusader-Extreme-Cover.gif";
    var bytes = await client.GetByteArrayAsync(url);
    var image = SixLabors.ImageSharp.Image.Load(bytes, out var format);
    Console.WriteLine(format);
}
catch (Exception e)
{
    Console.WriteLine(e.Message);
    Console.WriteLine(e.StackTrace);
    Debugger.Break();
}

Images

Stronghold-Crusader-Extreme-Cover

Activity

  1. JimBobSquarePants commented on Feb 18, 2022

    @JimBobSquarePants
    Member

    Confirmed. Memory access violation in LzwDecoder. Will compare GifDecoderCore in 1.0.4 with the one from main to see what I can spot. It's likely got something to do with our new XMP functionality as I've already checked the missing colortable fix.

  2. added this to the 2.*.* milestone on Feb 18, 2022
  3. JimBobSquarePants commented on Feb 18, 2022

    @JimBobSquarePants
    Member

    It's definitely the XMP application extension handling. I've fixed the reader so far but it looks like the writer does not match the specification also and is not writing the data in subblocks..

  4. added a commit that references this issue on Feb 18, 2022
    8db4828
  5. paulyipkh commented on Feb 19, 2022

    @paulyipkh
    Author

    Here is another gif file which even fails the v1.0.4 https://www.rxlist.com/images/rxlist/drona1.gif

  6. JimBobSquarePants commented on Feb 19, 2022

    @JimBobSquarePants
    Member

    Here is another gif file which even fails the v1.0.4

    That image is actually corrupt. The minimum code specified is greater than the specification allows.

    Windows Explorer can't open it, nor can Photos, Paint, or Paint.NET.

    Edge can though, as can VS Code, returning it as a 276 x 49135 transparent gif which is actually incorrect according to the specification because there's no Graphic Control Extension present in the image and thus no transparency flag.

    I can update the decoder to simply ignore frame indices data if it's corrupt. This will return a 276 x 49135 black gif.

  7. paulyipkh commented on Feb 19, 2022

    @paulyipkh
    Author

    From time to time, corrupted image would be encountered. The main problem is that an unmanaged exception would be thrown and the process would be terminated. Is it possible to catch the unmanaged exception and throw a managed one so that the situation could be handled in the C# code ?

  8. JimBobSquarePants commented on Feb 19, 2022

    @JimBobSquarePants
    Member

    Did you read the referenced PR?

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions