From 44c1ad58b19c25934fdb0b58db63709bda3f27f9 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 21 May 2022 22:31:18 +0200 Subject: [PATCH] Use flag to indicate if JFIF marker is present (invalid markers also count) --- src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index e1e6d5d6e9..1e7f5a92e3 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -90,6 +90,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg /// private JFifMarker jFif; + /// + /// Whether the image has a JFIF marker. This is needed to determine, if the colorspace is YCbCr. + /// + private bool hasJFif; + /// /// Contains information about the Adobe marker. /// @@ -519,7 +524,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg return JpegColorSpace.RGB; } - if (!this.jFif.Equals(default)) + if (this.hasJFif) { // JFIF implies YCbCr. return JpegColorSpace.YCbCr; @@ -721,6 +726,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg /// The remaining bytes in the segment block. private void ProcessApplicationHeaderMarker(BufferedReadStream stream, int remaining) { + this.hasJFif = true; + // We can only decode JFif identifiers. // Some images contain multiple JFIF markers (Issue 1932) so we check to see // if it's already been read.