Browse Source

Fix #115

af/merge-core
James Jackson-South 9 years ago
parent
commit
c45b945489
  1. 9
      src/ImageSharp.Formats.Png/PngDecoderCore.cs
  2. 3
      tests/ImageSharp.Tests/FileTestBase.cs
  3. 9
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      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.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using static ComparableExtensions; using static ComparableExtensions;
@ -945,12 +946,7 @@ namespace ImageSharp.Formats
private void ReadChunkLength(PngChunk chunk) private void ReadChunkLength(PngChunk chunk)
{ {
int numBytes = this.currentStream.Read(this.chunkLengthBuffer, 0, 4); int numBytes = this.currentStream.Read(this.chunkLengthBuffer, 0, 4);
if (numBytes > 1 && numBytes <= 3) if (numBytes < 4)
{
throw new ImageFormatException("Image stream is not valid!");
}
if (numBytes <= 1)
{ {
chunk.Length = -1; chunk.Length = -1;
return; return;
@ -966,6 +962,7 @@ namespace ImageSharp.Formats
/// </summary> /// </summary>
/// <param name="pass">Th current pass index</param> /// <param name="pass">Th current pass index</param>
/// <returns>The <see cref="int"/></returns> /// <returns>The <see cref="int"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private int ComputeColumnsAdam7(int pass) private int ComputeColumnsAdam7(int pass)
{ {
int width = this.header.Width; 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.Car),
// TestFile.Create(TestImages.Bmp.Neg_height), // Perf: Enable for local testing only // TestFile.Create(TestImages.Bmp.Neg_height), // Perf: Enable for local testing only
TestFile.Create(TestImages.Png.Splash), 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.Powerpoint), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Blur), // 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.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 SplashInterlaced = "Png/splash-interlaced.png";
public const string Interlaced = "Png/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 Filter0 = "Png/filter0.png";
public const string Filter1 = "Png/filter1.png"; public const string Filter1 = "Png/filter1.png";
public const string Filter2 = "Png/filter2.png"; public const string Filter2 = "Png/filter2.png";
public const string Filter3 = "Png/filter3.png"; public const string Filter3 = "Png/filter3.png";
public const string Filter4 = "Png/filter4.png"; public const string Filter4 = "Png/filter4.png";
// filter changing per scanline // Filter changing per scanline
public const string FilterVar = "Png/filterVar.png"; public const string FilterVar = "Png/filterVar.png";
// Chunk length of 1 by end marker // Odd chunk lengths
public const string ChunkLength = "Png/chunklength1.png"; public const string ChunkLength1 = "Png/chunklength1.png";
public const string ChunkLength2 = "Png/chunklength2.png";
} }
public static class Jpeg public static class Jpeg

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

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