Skip to content

Commit b2ac9bb

Browse files
Merge pull request #2482 from SixLabors/js/jpeg_JFXX
Allow JFXX as an App0 marker header
2 parents c68be04 + 9f0fba4 commit b2ac9bb

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ private JFifMarker(byte majorVersion, byte minorVersion, byte densityUnits, shor
7171
/// <param name="marker">The marker to return.</param>
7272
public static bool TryParse(ReadOnlySpan<byte> bytes, out JFifMarker marker)
7373
{
74-
if (ProfileResolver.IsProfile(bytes, ProfileResolver.JFifMarker))
74+
// Some images incorrectly use JFXX as the App0 marker (Issue 2478)
75+
if (ProfileResolver.IsProfile(bytes, ProfileResolver.JFifMarker)
76+
|| ProfileResolver.IsProfile(bytes, ProfileResolver.JFxxMarker))
7577
{
7678
byte majorVersion = bytes[5];
7779
byte minorVersion = bytes[6];

src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ internal static class ProfileResolver
1616
(byte)'J', (byte)'F', (byte)'I', (byte)'F', (byte)'\0'
1717
};
1818

19+
/// <summary>
20+
/// Gets the JFXX specific markers.
21+
/// </summary>
22+
public static ReadOnlySpan<byte> JFxxMarker => new[]
23+
{
24+
(byte)'J', (byte)'F', (byte)'X', (byte)'X', (byte)'\0'
25+
};
26+
1927
/// <summary>
2028
/// Gets the ICC specific markers.
2129
/// </summary>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,15 @@ public void Issue2315_DecodeWorks<TPixel>(TestImageProvider<TPixel> provider)
314314
image.DebugSave(provider);
315315
image.CompareToOriginal(provider);
316316
}
317+
318+
// https://github.com/SixLabors/ImageSharp/issues/2478
319+
[Theory]
320+
[WithFile(TestImages.Jpeg.Issues.Issue2478_JFXX, PixelTypes.Rgba32)]
321+
public void Issue2478_DecodeWorks<TPixel>(TestImageProvider<TPixel> provider)
322+
where TPixel : unmanaged, IPixel<TPixel>
323+
{
324+
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
325+
image.DebugSave(provider);
326+
image.CompareToOriginal(provider);
327+
}
317328
}

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ public static class Issues
290290
public const string Issue2315_NotEnoughBytes = "Jpg/issues/issue-2315.jpg";
291291
public const string Issue2334_NotEnoughBytesA = "Jpg/issues/issue-2334-a.jpg";
292292
public const string Issue2334_NotEnoughBytesB = "Jpg/issues/issue-2334-b.jpg";
293+
public const string Issue2478_JFXX = "Jpg/issues/issue-2478-jfxx.jpg";
293294

294295
public static class Fuzz
295296
{
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)