diff --git a/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs b/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs index 71141a893..405eeafeb 100644 --- a/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs +++ b/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -140,7 +140,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib offset += bytesRead; - if (offset >= length) + if (offset >= length || offset >= count) { return bytesRead; } @@ -249,4 +249,4 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib this.compressedStream = new DeflateStream(this, CompressionMode.Decompress, true); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index 70d191d74..5bb2db784 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. // ReSharper disable InconsistentNaming @@ -42,7 +42,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png TestImages.Png.Rgb24BppTrans, TestImages.Png.GrayAlpha8Bit, TestImages.Png.Gray1BitTrans, - TestImages.Png.Bad.ZlibOverflow + TestImages.Png.Bad.ZlibOverflow, + TestImages.Png.Bad.ZlibOverflow2 }; public static readonly string[] TestImages48Bpp = @@ -294,4 +295,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 1019a5b08..3c732c32d 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -87,6 +87,7 @@ namespace SixLabors.ImageSharp.Tests public const string ChunkLength2 = "Png/chunklength2.png"; public const string CorruptedChunk = "Png/big-corrupted-chunk.png"; public const string ZlibOverflow = "Png/zlib-overflow.png"; + public const string ZlibOverflow2 = "Png/zlib-overflow2.png"; } public static readonly string[] All = diff --git a/tests/Images/Input/Png/zlib-overflow2.png b/tests/Images/Input/Png/zlib-overflow2.png new file mode 100644 index 000000000..bb95cfee8 --- /dev/null +++ b/tests/Images/Input/Png/zlib-overflow2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3994ef9f044fd589a412409b35cf23d346da43af0d82e25f2c11a36b464c7599 +size 16887