From 934e2bce34fb17060f66883c71f08e18aef4eaaf Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 3 May 2018 10:26:28 +1000 Subject: [PATCH] Skip SOS contents when parsing metadata only --- .../Jpeg/GolangPort/OrigJpegDecoderCore.cs | 15 +++++++++------ .../Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs | 6 +++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs index 6b4da1ba1..c7e26e04a 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs @@ -361,15 +361,18 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort break; case OrigJpegConstants.Markers.SOS: - if (!metadataOnly) + if (metadataOnly) { - this.ProcessStartOfScanMarker(remaining); + this.InputProcessor.Skip(remaining); } - - if (this.InputProcessor.ReachedEOF) + else { - // If unexpected EOF reached. We can stop processing bytes as we now have the image data. - processBytes = false; + this.ProcessStartOfScanMarker(remaining); + if (this.InputProcessor.ReachedEOF) + { + // If unexpected EOF reached. We can stop processing bytes as we now have the image data. + processBytes = false; + } } break; diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index c20f283d7..03ca170cf 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs @@ -246,7 +246,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort break; case PdfJsJpegConstants.Markers.SOS: - if (!metadataOnly) + if (metadataOnly) + { + this.InputStream.Skip(remaining); + } + else { this.ProcessStartOfScanMarker(); }