Imagesharp: PNG from web url fails to load or identify.

Created on 6 Nov 2019  路  5Comments  路  Source: SixLabors/ImageSharp

Prerequisites

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

Description

Downloading certain png as a byte array or a stream results in errors. Either "stream is invalid" or "png contains no data chunk" etc.

Steps to Reproduce

                var client = _httpClientFactory.CreateClient();
                var bytes = await client.GetStreamAsync(p.ImageUrl);
                var image = SixLabors.ImageSharp.Image.Load(bytes, new PngDecoder());

System Configuration

  • ImageSharp version: 1.0.0 beta 7.
  • Other ImageSharp packages and versions:
  • Environment (Operating system, version and so on): Windows 10 x64.
  • .NET Framework version: .Net Core 3.
  • Additional information:

Here are the images:
75c585ba-a391-e811-ad47-b8ca3a6870b8
0a2d3ae2-4f6e-e711-8cac-b8ca3a687730

question

All 5 comments

Try the following:

c# var client = _httpClientFactory.CreateClient(); using(var bytes = await client.GetStreamAsync(p.ImageUrl)) { // Remember to dispose of this image once you are finished. var image = SixLabors.ImageSharp.Image.Load(bytes, new PngDecoder()); }

It looks to me like you're having the same issue as https://github.com/SixLabors/ImageSharp/issues/1029#issuecomment-544061230

Switched to the suggested code, same issue. ImageFormatException: Image stream is not valid.

Edit: I did see similar issues, but I thought there might be something distinctly wrong with the png files in question. Maybe the metadata is off somehow, or something nonstandard is going on.

Edit#2: I ran both files through pngcheck, and it reports "EOF while reading CRC value."

What happens when you copy your input stream to a MemoryStream and load via that? Something is causing your stream not to flush.

I'm assuming of course, that the requests are successful.

Same thing happens.

Thanks for the extra info, I appreciate it.

I ran both files through pngcheck, and it reports "EOF while reading CRC value.
I have done some investigation and confirmed your findings. However we are attempting to read the crc data from those images and throwing an error whether they are critical or not. I will work on a fix asap.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JimBobSquarePants picture JimBobSquarePants  路  3Comments

nullpainter picture nullpainter  路  3Comments

vpenades picture vpenades  路  4Comments

olivif picture olivif  路  3Comments

xakep139 picture xakep139  路  3Comments