Browse Source

Ignore chunk length of 1. Fix #103

TODO: Read libpng for matching behaviour
af/merge-core
James Jackson-South 9 years ago
parent
commit
972e345ab8
  1. 4
      src/ImageSharp.Formats.Png/PngDecoderCore.cs
  2. 14
      tests/ImageSharp.Tests/FileTestBase.cs
  3. 3
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      tests/ImageSharp.Tests/TestImages/Formats/Png/chunklength1.png

4
src/ImageSharp.Formats.Png/PngDecoderCore.cs

@ -927,12 +927,12 @@ namespace ImageSharp.Formats
private void ReadChunkLength(PngChunk chunk)
{
int numBytes = this.currentStream.Read(this.chunkLengthBuffer, 0, 4);
if (numBytes >= 1 && numBytes <= 3)
if (numBytes > 1 && numBytes <= 3)
{
throw new ImageFormatException("Image stream is not valid!");
}
if (numBytes <= 0)
if (numBytes <= 1)
{
chunk.Length = -1;
return;

14
tests/ImageSharp.Tests/FileTestBase.cs

@ -6,7 +6,6 @@
namespace ImageSharp.Tests
{
using System.Collections.Generic;
using ImageSharp.Formats;
/// <summary>
/// The test base class for reading and writing to files.
@ -18,8 +17,8 @@ namespace ImageSharp.Tests
/// </summary>
protected static readonly List<TestFile> Files = new List<TestFile>
{
TestFile.Create(TestImages.Jpeg.Baseline.Calliphora),
TestFile.Create(TestImages.Jpeg.Baseline.Turtle),
TestFile.Create(TestImages.Jpeg.Baseline.Calliphora),
// TestFile.Create(TestImages.Jpeg.Baseline.Turtle), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Jpeg.Baseline.Ycck), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Jpeg.Baseline.Cmyk), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Jpeg.Baseline.Floorplan), // Perf: Enable for local testing only
@ -28,10 +27,11 @@ namespace ImageSharp.Tests
// TestFile.Create(TestImages.Jpeg.Progressive.Progress), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Jpeg.Baseline.GammaDalaiLamaGray), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Jpeg.Progressive.Bad.BadEOF), // Perf: Enable for local testing only
TestFile.Create(TestImages.Bmp.Car),
TestFile.Create(TestImages.Bmp.Car),
// TestFile.Create(TestImages.Bmp.Neg_height), // Perf: Enable for local testing only
TestFile.Create(TestImages.Png.Splash),
TestFile.Create(TestImages.Png.Powerpoint),
TestFile.Create(TestImages.Png.Splash),
// TestFile.Create(TestImages.Png.ChunkLength), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Powerpoint), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Blur), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Indexed), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.SplashInterlaced), // Perf: Enable for local testing only
@ -44,7 +44,7 @@ namespace ImageSharp.Tests
// TestFile.Create(TestImages.Png.FilterVar), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.P1), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Pd), // Perf: Enable for local testing only
TestFile.Create(TestImages.Gif.Rings), // Perf: Enable for local testing only
TestFile.Create(TestImages.Gif.Rings),
// TestFile.Create(TestImages.Gif.Cheers), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Gif.Giphy) // Perf: Enable for local testing only
};

3
tests/ImageSharp.Tests/TestImages.cs

@ -34,6 +34,9 @@ namespace ImageSharp.Tests
// filter changing per scanline
public const string FilterVar = "Png/filterVar.png";
// Chunk length of 1 by end marker
public const string ChunkLength = "Png/chunklength1.png";
}
public static class Jpeg

3
tests/ImageSharp.Tests/TestImages/Formats/Png/chunklength1.png

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7b9957a86738acc0b682618a6677c8d659614cd6be5728e85185aef314c21981
size 149591
Loading…
Cancel
Save