diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs index 6ee1d9e462..ca8bf10e53 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs @@ -245,7 +245,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { if (this.Bits.UnreadBits == 0) { - this.Bits.EnsureNBits(1, ref this); + this.LastErrorCode = this.Bits.EnsureNBitsUnsafe(1, ref this); + + if (this.HasError) + { + return this.LastErrorCode; + } } if ((this.Bits.Accumulator & this.Bits.Mask) != 0) diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.cs index c13d3cf745..2b31417cd8 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.cs @@ -137,6 +137,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder /// The instance public void DecodeBlocks(OrigJpegDecoderCore decoder) { + decoder.InputProcessor.ResetErrorState(); + int blockCount = 0; int mcu = 0; byte expectedRst = OrigJpegConstants.Markers.RST0; @@ -364,7 +366,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { int value; decoder.InputProcessor.DecodeHuffmanUnsafe(ref decoder.HuffmanTrees[huffmannIdx], out value); - if (!decoder.InputProcessor.CheckEOF()) + if (decoder.InputProcessor.HasError) { return; } @@ -381,11 +383,16 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder int ac; decoder.InputProcessor.ReceiveExtendUnsafe(val1, out ac); - if (!decoder.InputProcessor.CheckEOFEnsureNoError()) + if (decoder.InputProcessor.HasError) { return; } + //if (!decoder.InputProcessor.CheckEOFEnsureNoError()) + //{ + // return; + //} + // b[Unzig[zig]] = ac << al; value = ac << this.al; Block8x8.SetScalarAt(b, this.pointers.Unzig[zig], (short)value); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 32934ec9d7..ae49e930da 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -37,8 +37,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg TestImages.Jpeg.Baseline.Jpeg444, TestImages.Jpeg.Baseline.Bad.BadEOF, TestImages.Jpeg.Baseline.Bad.ExifUndefType, - - TestImages.Jpeg.Issues.MissingFF00Gear159, }; public static string[] ProgressiveTestJpegs = diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index e9deb16af6..f6e493233d 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -117,7 +117,6 @@ namespace SixLabors.ImageSharp.Tests { public const string CriticalEOF214 = "Jpg/issues/Issue214-CriticalEOF.jpg"; public const string MissingFF00ProgressiveGirl159 = "Jpg/issues/Issue159-MissingFF00-Progressive-Girl.jpg"; - public const string MissingFF00Gear159 = "Jpg/issues/Issue159-MissingFF00-Gear.jpg"; public const string BadCoeffsProgressive178 = "Jpg/issues/Issue178-BadCoeffsProgressive-Lemon.jpg"; }