Imagesharp: Image.Load with interlaced PNG files: System.ArgumentOutOfRangeException : Non-negative number required. Parameter name: count

Created on 26 Apr 2017  Â·  7Comments  Â·  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

Exception happens when files loaded from stream. It only happens with some interlaced PNG files, particularly with the following 2 files
invalidpngwithinterlacing
91c3ae_fdc3323aeacf4744b1ff1418c8f100d2

I have tested the same code with interlaced PNG from your repository plash-interlaced.png and it was successfully loaded.

Steps to Reproduce

               using (var fileStream = File.OpenWrite(filePath))
                {
                          input.Seek(0, SeekOrigin.Begin);> 
                          var image = Image.Load(input);
                }

Exception is:

System.ArgumentOutOfRangeException : Non-negative number required. Parameter name: count at System.IO.Win32FileStream.Read(Byte[] array, Int32 offset, Int32 count) at System.IO.FileStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.IO.Compression.DeflateStream.Read(Byte[] array, Int32 offset, Int32 count) at ImageSharp.Formats.ZlibInflateStream.Read(Byte[] buffer, Int32 offset, Int32 count) at ImageSharp.Formats.PngDecoderCore.DecodeInterlacedPixelData[TPixel](Stream compressedStream, PixelAccessor1 pixels) at ImageSharp.Formats.PngDecoderCore.Decode[TPixel](Stream stream) at ImageSharp.Formats.PngDecoder.Decode[TPixel](Configuration configuration, Stream stream, IDecoderOptions options) at ImageSharp.Image.Decode[TPixel](Stream stream, IDecoderOptions options, Configuration config) at ImageSharp.Image.Load[TPixel](Configuration config, Stream stream, IDecoderOptions options) at ImageSharp.Image.Load(Stream stream)

System Configuration

  • ImageSharp version: 1.0.0-alpha7-00012
  • Other ImageSharp packages and versions:
  • Environment (Operating system, version and so on): Windows 10 , VS 2017
  • .NET Framework version: 1.2
  • Additional information:
formats bug png

All 7 comments

@Drawaes When you have some time could you possibly have a look at this?

I've been trying to debug the issue for a couple of hours now to no avail.

From what I can see the crc reading that is taking place within ZlibInflateStream is causing the private currentDataRemaining field in DeframeStream to be negative -4. Then, and I'm not sure how it's getting called, DeframeStream.Read(byte[] buffer, int offset, int count) is called which throws our error.

I'm a wee bit stumped.

I think I know what the issue is without looking at it. But I would need
the exact test image.

On 27/04/2017 4:11 AM, "James Jackson-South" notifications@github.com
wrote:

@Drawaes https://github.com/Drawaes When you have some time could you
possibly have a look at this?

I've been trying to debug the issue for a couple of hours now to no avail.

From what I can see the crc reading that is taking place within
ZlibInflateStream is causing the private currentDataRemaining field in
DeframeStream to be negative -4. Then, and I'm not sure how it's getting
called DeframeStream.Read(byte[] buffer, int offset, int count) is called
which throws our error.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/JimBobSquarePants/ImageSharp/issues/191#issuecomment-297599433,
or mute the thread
https://github.com/notifications/unsubscribe-auth/APpZuQ9wL44k1o3J-YFJ3dzOk0LriADSks5r0AdbgaJpZM4NJJ8h
.

I am pretty sure I know how to fix it and it will make it faster at the same time.

Wizzzzzzaaaard!

Okay I have a fix for that bug, but it has highlighted another issue with the interlaced PNG. I will work on fixing that tonight.

@srudenko This is now fixed with #196 Should be good to go 😄

I can confirm that the issue has been fixed in 1.0.0-alpha8-00058. Tested using different types of images including the provided.,

Was this page helpful?
0 / 5 - 0 ratings