Browse Source
Merge pull request #3072 from SixLabors/js/fix-3071
JPEG - Throw explicit ImageContentException on missing marker.
pull/3075/head
James Jackson-South
2 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
14 additions and
0 deletions
-
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
-
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.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; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -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); |
|
|
|
}); |
|
|
|
} |
|
|
|
|