Skip to content

Image.Load throws an ArgumentException when loading PNG #849

@casperOne

Description

@casperOne

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

Description

Loading the following PNG (from a Stream or ReadOnlyMemory<byte> instance) throws an ArgumentException.

https://user-images.githubusercontent.com/561862/54476020-e3ab4c00-47ce-11e9-9cb1-2542507bf23c.png

Which has the following message:

Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.

Notes:

  • The image renders in Chrome correctly
  • According to http://www.libpng.org/pub/png/apps/pngcheck.html, there are no problems with image integrity
  • There are three IDAT sections in the PNG (this shouldn't make a difference, from what I can tell in my reading of the spec)
  • The images are produced out of FFMPEG, but other PNG images output from the same process/video are able to be loaded

Steps to Reproduce

Use the above image in a FileStream (or any Stream representation).

Load the image (this can be copied/pasted into a .NET Core 2.2 console app and the ImageSharp libraries referenced):

static async Task Main()
{
    try
    {
        // Use http client.
        var client = new HttpClient();

        // Make the request.
        using (Stream stream = await client.GetStreamAsync(
                "https://user-images.githubusercontent.com/561862/54476020-e3ab4c00-47ce-11e9-9cb1-2542507bf23c.png")
            .ConfigureAwait(false))
        {
            Image<Rgba32> image = Image.Load<Rgba32>(stream, new PngDecoder());
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e);
        throw;
    }
}

System Configuration

  • ImageSharp version: 1.0.0-beta0006
  • Other ImageSharp packages and versions: None
  • Environment (Operating system, version and so on): Windows 10
  • .NET Framework version: .NET Core 2.2
  • Additional information:

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions