Skip to content

Commit

Permalink
Merge pull request #801 from jongleur1983/797-LoadThrowsNRE-bySharpFuzz
Browse files Browse the repository at this point in the history
#797 throw ImageFormatException when no StartOfFrame marker is found
  • Loading branch information
JimBobSquarePants committed Jan 6, 2019
2 parents db0fc0d + 59d76a0 commit 441942b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
Expand Up @@ -859,6 +859,11 @@ private void ProcessDefineRestartIntervalMarker(int remaining)
/// </summary>
private void ProcessStartOfScanMarker()
{
if (this.Frame is null)
{
throw new ImageFormatException("No readable SOFn (Start Of Frame) marker found.");
}

int selectorsCount = this.InputStream.ReadByte();
for (int i = 0; i < selectorsCount; i++)
{
Expand Down
Expand Up @@ -42,5 +42,13 @@ public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow<TPixel>(TestImageProvider
// TODO: We need a public ImageDecoderException class in ImageSharp!
Assert.ThrowsAny<Exception>(() => provider.GetImage(JpegDecoder));
}

[Theory]
[WithFile(TestImages.Jpeg.Issues.InvalidJpegThrowsWrongException797, PixelTypes.Rgba32)]
public void LoadingImage_InvalidTagLength_ShouldThrow<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
Assert.Throws<ImageFormatException>(() => provider.GetImage());
}
}
}
1 change: 1 addition & 0 deletions tests/ImageSharp.Tests/TestImages.cs
Expand Up @@ -167,6 +167,7 @@ public static class Issues
public const string OrderedInterleavedProgressive723C = "Jpg/issues/Issue723-Ordered-Interleaved-Progressive-C.jpg";
public const string ExifGetString750Transform = "Jpg/issues/issue750-exif-tranform.jpg";
public const string ExifGetString750Load = "Jpg/issues/issue750-exif-load.jpg";
public const string InvalidJpegThrowsWrongException797 = "Jpg/issues/Issue797-InvalidImage.jpg";
}

public static readonly string[] All = Baseline.All.Concat(Progressive.All).ToArray();
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 441942b

Please sign in to comment.