Browse Source

Allow JFXX as an App0 marker header

pull/2482/head
James Jackson-South 3 years ago
parent
commit
492507fa2d
  1. 4
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs
  2. 8
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs
  3. 11
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  4. 1
      tests/ImageSharp.Tests/TestImages.cs
  5. 3
      tests/Images/Input/Jpg/issues/issue-2478-jfxx.jpg

4
src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs

@ -71,7 +71,9 @@ internal readonly struct JFifMarker : IEquatable<JFifMarker>
/// <param name="marker">The marker to return.</param>
public static bool TryParse(ReadOnlySpan<byte> 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];

8
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'
};
/// <summary>
/// Gets the JFXX specific markers.
/// </summary>
public static ReadOnlySpan<byte> JFxxMarker => new[]
{
(byte)'J', (byte)'F', (byte)'X', (byte)'X', (byte)'\0'
};
/// <summary>
/// Gets the ICC specific markers.
/// </summary>

11
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -314,4 +314,15 @@ public partial class JpegDecoderTests
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<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
}

1
tests/ImageSharp.Tests/TestImages.cs

@ -290,6 +290,7 @@ public static class TestImages
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
{

3
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
Loading…
Cancel
Save