Browse Source

#797 throw ImageFormatException when no StartOfFrame marker is found on a jpg image.

af/merge-core
Peter Amrehn 7 years ago
parent
commit
880be0a5aa
  1. 5
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  2. 8
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs
  3. 1
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      tests/Images/Input/Jpg/issues/Issue797-InvalidImage.jpg

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

@ -292,6 +292,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
case JpegConstants.Markers.SOS:
if (!metadataOnly)
{
if (this.Frame is null)
{
throw new ImageFormatException("no readable SOF marker found.");
}
this.ProcessStartOfScanMarker();
break;
}

8
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs

@ -42,5 +42,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
// 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
tests/ImageSharp.Tests/TestImages.cs

@ -167,6 +167,7 @@ namespace SixLabors.ImageSharp.Tests
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();

3
tests/Images/Input/Jpg/issues/Issue797-InvalidImage.jpg

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2c3c6a09c1ed868bb18c7c5038da743a88dbfd10762a2b12260053adf63b376f
size 381
Loading…
Cancel
Save