Browse Source

Fix #937 (#938)

pull/952/head
James Jackson-South 7 years ago
committed by GitHub
parent
commit
692e244f9a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs
  2. 7
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  3. 1
      tests/ImageSharp.Tests/TestImages.cs
  4. BIN
      tests/Images/Input/Png/zlib-overflow2.png

6
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. // Licensed under the Apache License, Version 2.0.
using System; using System;
@ -140,7 +140,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
offset += bytesRead; offset += bytesRead;
if (offset >= length) if (offset >= length || offset >= count)
{ {
return bytesRead; return bytesRead;
} }
@ -249,4 +249,4 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
this.compressedStream = new DeflateStream(this, CompressionMode.Decompress, true); this.compressedStream = new DeflateStream(this, CompressionMode.Decompress, true);
} }
} }
} }

7
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. // Licensed under the Apache License, Version 2.0.
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
@ -42,7 +42,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
TestImages.Png.Rgb24BppTrans, TestImages.Png.Rgb24BppTrans,
TestImages.Png.GrayAlpha8Bit, TestImages.Png.GrayAlpha8Bit,
TestImages.Png.Gray1BitTrans, TestImages.Png.Gray1BitTrans,
TestImages.Png.Bad.ZlibOverflow TestImages.Png.Bad.ZlibOverflow,
TestImages.Png.Bad.ZlibOverflow2
}; };
public static readonly string[] TestImages48Bpp = public static readonly string[] TestImages48Bpp =
@ -294,4 +295,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
} }
} }
} }
} }

1
tests/ImageSharp.Tests/TestImages.cs

@ -87,6 +87,7 @@ namespace SixLabors.ImageSharp.Tests
public const string ChunkLength2 = "Png/chunklength2.png"; public const string ChunkLength2 = "Png/chunklength2.png";
public const string CorruptedChunk = "Png/big-corrupted-chunk.png"; public const string CorruptedChunk = "Png/big-corrupted-chunk.png";
public const string ZlibOverflow = "Png/zlib-overflow.png"; public const string ZlibOverflow = "Png/zlib-overflow.png";
public const string ZlibOverflow2 = "Png/zlib-overflow2.png";
} }
public static readonly string[] All = public static readonly string[] All =

BIN
tests/Images/Input/Png/zlib-overflow2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Loading…
Cancel
Save