diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs index 6426afd49..a3967c739 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs +++ b/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) { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 9247a1fdc..5f0b08ed1 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/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(TestImageProvider 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(TestImageProvider provider) + where TPixel : struct, IPixel + { + // TODO: We need a public ImageDecoderException class in ImageSharp! + Assert.ThrowsAny(() => provider.GetImage(OrigJpegDecoder)); + } + public const string DecodeProgressiveJpegOutputName = "DecodeProgressiveJpeg"; [Theory] diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 252eab483..c36f02259 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/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(); } diff --git a/tests/Images/Input/Jpg/issues/Issue214-CriticalEOF .jpg b/tests/Images/Input/Jpg/issues/Issue214-CriticalEOF .jpg new file mode 100644 index 000000000..84b22c9da Binary files /dev/null and b/tests/Images/Input/Jpg/issues/Issue214-CriticalEOF .jpg differ