Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image.Load throws an ArgumentException when loading PNG #849

Closed
3 of 4 tasks
casperOne opened this issue Mar 16, 2019 · 6 comments
Closed
3 of 4 tasks

Image.Load throws an ArgumentException when loading PNG #849

casperOne opened this issue Mar 16, 2019 · 6 comments
Assignees
Milestone

Comments

@casperOne
Copy link

casperOne commented Mar 16, 2019

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:
@clintonrocksmith
Copy link

Hi there,

I did find this as an issue but had to set the decoder explicitly to being a png otherwise it failed. This was in a .NET Core solution as well whereby I loaded via a stream from Blob Storage in Azure, just giving more information to help.

@casperOne
Copy link
Author

casperOne commented Mar 19, 2019

@clintonrocksmith Thanks for the reply, much appreciated.

That said, I didn't have any luck setting the decoder explicitly. Using HttpClient to download the link above, I still get the same error using this:

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;
    }
}

May I ask how you were able to get it to load?

@JimBobSquarePants
Copy link
Member

@casperOne @clintonrocksmith The two issues are not related. There’s something about that png that causes our current decoder to fail. I fixed the issue locally today though.

The other issue sounds like it was due to the input stream being in the wrong position for us to identify the decoder.

@casperOne
Copy link
Author

@JimBobSquarePants Thanks for the follow-up. I'll keep an eye on this to be closed when a PR gets merged. Looking forward to the next push to Nuget for the fix.

Thanks!

@JimBobSquarePants
Copy link
Member

@casperOne Don't forget we have rock solid development releases on Myget

https://github.com/SixLabors/ImageSharp#installation

@casperOne
Copy link
Author

@JimBobSquarePants Thanks for addressing this, I've confirmed this works, and have used the MyGet repository.

antonfirsov pushed a commit to antonfirsov/ImageSharp that referenced this issue Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants