Browse Source

Fix #115

pull/22/merge
James Jackson-South 9 years ago
parent
commit
90de26fbe5
  1. 9
      src/ImageSharp.Formats.Png/PngDecoderCore.cs
  2. 3
      tests/ImageSharp.Tests/FileTestBase.cs
  3. 9
      tests/ImageSharp.Tests/TestImages.cs
  4. BIN
      tests/ImageSharp.Tests/TestImages/Formats/Png/chunklength2.png

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

@ -10,6 +10,7 @@ namespace ImageSharp.Formats
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using static ComparableExtensions;
@ -945,12 +946,7 @@ namespace ImageSharp.Formats
private void ReadChunkLength(PngChunk chunk)
{
int numBytes = this.currentStream.Read(this.chunkLengthBuffer, 0, 4);
if (numBytes > 1 && numBytes <= 3)
{
throw new ImageFormatException("Image stream is not valid!");
}
if (numBytes <= 1)
if (numBytes < 4)
{
chunk.Length = -1;
return;
@ -966,6 +962,7 @@ namespace ImageSharp.Formats
/// </summary>
/// <param name="pass">Th current pass index</param>
/// <returns>The <see cref="int"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private int ComputeColumnsAdam7(int pass)
{
int width = this.header.Width;

3
tests/ImageSharp.Tests/FileTestBase.cs

@ -30,7 +30,8 @@ namespace ImageSharp.Tests
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.ChunkLength), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.ChunkLength1), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.ChunkLength2), // 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

9
tests/ImageSharp.Tests/TestImages.cs

@ -25,18 +25,19 @@ namespace ImageSharp.Tests
public const string SplashInterlaced = "Png/splash-interlaced.png";
public const string Interlaced = "Png/interlaced.png";
// filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html
// Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html
public const string Filter0 = "Png/filter0.png";
public const string Filter1 = "Png/filter1.png";
public const string Filter2 = "Png/filter2.png";
public const string Filter3 = "Png/filter3.png";
public const string Filter4 = "Png/filter4.png";
// filter changing per scanline
// 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";
// Odd chunk lengths
public const string ChunkLength1 = "Png/chunklength1.png";
public const string ChunkLength2 = "Png/chunklength2.png";
}
public static class Jpeg

BIN
tests/ImageSharp.Tests/TestImages/Formats/Png/chunklength2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Loading…
Cancel
Save