diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs index 153dc8a03e..7e25e945a5 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs @@ -71,7 +71,9 @@ private JFifMarker(byte majorVersion, byte minorVersion, byte densityUnits, shor /// The marker to return. public static bool TryParse(ReadOnlySpan bytes, out JFifMarker marker) { - if (ProfileResolver.IsProfile(bytes, ProfileResolver.JFifMarker)) + // Some images incorrectly use JFXX as the App0 marker (Issue 2478) + if (ProfileResolver.IsProfile(bytes, ProfileResolver.JFifMarker) + || ProfileResolver.IsProfile(bytes, ProfileResolver.JFxxMarker)) { byte majorVersion = bytes[5]; byte minorVersion = bytes[6]; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs index 795f21a57f..c11679feb1 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs @@ -16,6 +16,14 @@ internal static class ProfileResolver (byte)'J', (byte)'F', (byte)'I', (byte)'F', (byte)'\0' }; + /// + /// Gets the JFXX specific markers. + /// + public static ReadOnlySpan JFxxMarker => new[] + { + (byte)'J', (byte)'F', (byte)'X', (byte)'X', (byte)'\0' + }; + /// /// Gets the ICC specific markers. /// diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 80789178d1..594e7ebe71 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -314,4 +314,15 @@ public void Issue2315_DecodeWorks(TestImageProvider provider) image.DebugSave(provider); image.CompareToOriginal(provider); } + + // https://github.com/SixLabors/ImageSharp/issues/2478 + [Theory] + [WithFile(TestImages.Jpeg.Issues.Issue2478_JFXX, PixelTypes.Rgba32)] + public void Issue2478_DecodeWorks(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + using Image image = provider.GetImage(JpegDecoder.Instance); + image.DebugSave(provider); + image.CompareToOriginal(provider); + } } diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index c4eb866c7c..95c9ac6732 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -290,6 +290,7 @@ public static class Issues public const string Issue2315_NotEnoughBytes = "Jpg/issues/issue-2315.jpg"; public const string Issue2334_NotEnoughBytesA = "Jpg/issues/issue-2334-a.jpg"; public const string Issue2334_NotEnoughBytesB = "Jpg/issues/issue-2334-b.jpg"; + public const string Issue2478_JFXX = "Jpg/issues/issue-2478-jfxx.jpg"; public static class Fuzz { diff --git a/tests/Images/Input/Jpg/issues/issue-2478-jfxx.jpg b/tests/Images/Input/Jpg/issues/issue-2478-jfxx.jpg new file mode 100644 index 0000000000..e65433c696 --- /dev/null +++ b/tests/Images/Input/Jpg/issues/issue-2478-jfxx.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6bd5d14cbbead348404511801d7a2bacab19174e9f4063b5d2cec96f28fd578e +size 300170