diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
index 011b6100dc..e3b0b4bdc6 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
@@ -510,7 +510,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// The remaining bytes in the segment block.
private void ProcessApplicationHeaderMarker(int remaining)
{
- if (remaining < 5)
+ // We can only decode JFif identifiers.
+ if (remaining < JFifMarker.Length)
{
// Skip the application header length
this.InputStream.Skip(remaining);
diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs
index a14c4735f5..2f041e3ab4 100644
--- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs
+++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs
@@ -25,7 +25,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
TestImages.Jpeg.Issues.MultiHuffmanBaseline394,
TestImages.Jpeg.Issues.ExifDecodeOutOfRange694,
TestImages.Jpeg.Issues.InvalidEOI695,
- TestImages.Jpeg.Issues.ExifResizeOutOfRange696
+ TestImages.Jpeg.Issues.ExifResizeOutOfRange696,
+ TestImages.Jpeg.Issues.InvalidAPP0721
};
public static string[] ProgressiveTestJpegs =
@@ -54,7 +55,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159
};
- private static readonly Dictionary CustomToleranceValues =
+ private static readonly Dictionary CustomToleranceValues =
new Dictionary
{
// Baseline:
diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs
index acfad042eb..309fb1d4ab 100644
--- a/tests/ImageSharp.Tests/TestImages.cs
+++ b/tests/ImageSharp.Tests/TestImages.cs
@@ -155,6 +155,7 @@ namespace SixLabors.ImageSharp.Tests
public const string ExifDecodeOutOfRange694 = "Jpg/issues/Issue694-Decode-Exif-OutOfRange.jpg";
public const string InvalidEOI695 = "Jpg/issues/Issue695-Invalid-EOI.jpg";
public const string ExifResizeOutOfRange696 = "Jpg/issues/Issue696-Resize-Exif-OutOfRange.jpg";
+ public const string InvalidAPP0721 = "Jpg/issues/Issue721-InvalidAPP0.jpg";
}
public static readonly string[] All = Baseline.All.Concat(Progressive.All).ToArray();
diff --git a/tests/Images/External b/tests/Images/External
index 7f4d2d64c6..5f3cbd839f 160000
--- a/tests/Images/External
+++ b/tests/Images/External
@@ -1 +1 @@
-Subproject commit 7f4d2d64c6b820ca2b6827e6a8540a1013305ccf
+Subproject commit 5f3cbd839fbbffae615d294d1dabafdcabc64cf9
diff --git a/tests/Images/Input/Jpg/issues/Issue721-InvalidAPP0.jpg b/tests/Images/Input/Jpg/issues/Issue721-InvalidAPP0.jpg
new file mode 100644
index 0000000000..6fa3bf660e
Binary files /dev/null and b/tests/Images/Input/Jpg/issues/Issue721-InvalidAPP0.jpg differ