Browse Source

JPEG - Throw explicit ImageContentException on missing marker.

pull/3072/head
James Jackson-South 2 months ago
parent
commit
ae6bdbf36f
  1. 5
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  2. 9
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

5
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -519,6 +519,11 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
fileMarker = FindNextFileMarker(stream);
}
if (!metadataOnly && this.Frame is null)
{
JpegThrowHelper.ThrowInvalidImageContentException("No readable SOFn (Start Of Frame) marker found.");
}
this.Metadata.GetJpegMetadata().Interleaved = this.Frame.Interleaved;
}

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

@ -448,4 +448,13 @@ public partial class JpegDecoderTests
[InlineData(TestImages.Jpeg.Issues.Issue2948)]
public void Issue2948_No_SOS_Identify_Throws_InvalidImageContentException(string imagePath)
=> Assert.Throws<InvalidImageContentException>(() => _ = Image.Identify(TestFile.Create(imagePath).Bytes));
[Fact]
public void Issue_3071_Decode_TruncatedJpeg_Throws_InvalidImageContentException()
=> Assert.Throws<InvalidImageContentException>(() =>
{
// SOI marker (FF D8) + garbage bytes — only 11 bytes
byte[] data = [0xFF, 0xD8, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30];
using Image<Rgba32> image = Image.Load<Rgba32>(data);
});
}

Loading…
Cancel
Save