Browse Source

fixed #214

pull/322/head
Anton Firszov 9 years ago
parent
commit
f11fc034d2
  1. 2
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs
  2. 16
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  3. 7
      tests/ImageSharp.Tests/TestImages.cs
  4. BIN
      tests/Images/Input/Jpg/issues/Issue214-CriticalEOF .jpg

2
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs

@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
}
OrigDecoderErrorCode errorCode = OrigDecoderErrorCode.NoError;
while (length > 0)
while (length > 0 && errorCode == OrigDecoderErrorCode.NoError)
{
if (this.Bytes.J - this.Bytes.I >= length)
{

16
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -4,6 +4,9 @@
// ReSharper disable InconsistentNaming
using System;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using System.IO;
@ -33,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
TestImages.Jpeg.Baseline.Jpeg420Small,
TestImages.Jpeg.Baseline.Jpeg444,
TestImages.Jpeg.Baseline.Bad.BadEOF,
TestImages.Jpeg.Baseline.Bad.ExifUndefType,
TestImages.Jpeg.Baseline.Bad.ExifUndefType
};
public static string[] ProgressiveTestJpegs =
@ -117,7 +120,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
image.CompareToReferenceOutput(provider, VeryTolerantJpegComparer, appendPixelTypeToFileName: false);
}
}
[Theory]
[WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)]
public void DecodeBaselineJpeg_Orig<TPixel>(TestImageProvider<TPixel> provider)
@ -132,6 +135,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
}
}
[Theory]
[WithFile(TestImages.Jpeg.Issues.Issue214CriticalEOF, PixelTypes.Rgba32)]
public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow_Orig<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
// TODO: We need a public ImageDecoderException class in ImageSharp!
Assert.ThrowsAny<Exception>(() => provider.GetImage(OrigJpegDecoder));
}
public const string DecodeProgressiveJpegOutputName = "DecodeProgressiveJpeg";
[Theory]

7
tests/ImageSharp.Tests/TestImages.cs

@ -112,6 +112,13 @@ namespace SixLabors.ImageSharp.Tests
};
}
public class Issues
{
public const string Issue214CriticalEOF = "Jpg/issues/Issue214-CriticalEOF .jpg";
public const string Issue159Girl = "Jpg/issues/Issue159Girl.jpg";
public const string Issue178Lemon = "Jpg/issues/Issue178.jpg";
}
public static readonly string[] All = Baseline.All.Concat(Progressive.All).ToArray();
}

BIN
tests/Images/Input/Jpg/issues/Issue214-CriticalEOF .jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Loading…
Cancel
Save