Skip to content

Commit

Permalink
SixLabors#797 throw ImageFormatException when no StartOfFrame marker …
Browse files Browse the repository at this point in the history
…is found on a jpg image.
  • Loading branch information
jongleur1983 committed Jan 4, 2019
1 parent db0fc0d commit 575c23d
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
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ public void ParseStream(Stream stream, bool metadataOnly = false)
case JpegConstants.Markers.SOS:
if (!metadataOnly)
{
if (this.Frame is null)
{
throw new ImageFormatException("no readable SOF marker found.");
}

this.ProcessStartOfScanMarker();
break;
}
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading
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 575c23d

Please sign in to comment.