Browse Source

Merge branch 'master' into release/rc-1

pull/1574/head
James Jackson-South 6 years ago
parent
commit
fe22a4560a
  1. 14
      src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs
  2. 4
      src/ImageSharp/Formats/Bmp/BmpDecoder.cs
  3. 7
      src/ImageSharp/Formats/Gif/GifDecoder.cs
  4. 8
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  5. 12
      src/ImageSharp/Formats/Gif/GifThrowHelper.cs
  6. 8
      src/ImageSharp/Formats/Gif/README.md
  7. 7
      src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
  8. 9
      src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs
  9. 7
      src/ImageSharp/Formats/Png/PngDecoder.cs
  10. 24
      src/ImageSharp/Formats/Png/PngMetadata.cs
  11. 4
      src/ImageSharp/Formats/Png/PngThrowHelper.cs
  12. 7
      src/ImageSharp/Formats/Tga/TgaDecoder.cs
  13. 14
      src/ImageSharp/Formats/Tga/TgaThrowHelper.cs
  14. 2
      tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
  15. 84
      tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
  16. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  17. 2
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  18. 2
      tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs
  19. 7
      tests/ImageSharp.Tests/TestImages.cs
  20. 2
      tests/Images/External
  21. 3
      tests/Images/Input/Gif/image-zero-height.gif
  22. 3
      tests/Images/Input/Gif/image-zero-size.gif
  23. 3
      tests/Images/Input/Gif/image-zero-width.gif
  24. 3
      tests/Images/Input/Gif/max-height.gif
  25. 3
      tests/Images/Input/Gif/max-width.gif

14
src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs

@ -1,6 +1,8 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp
{ {
/// <summary> /// <summary>
@ -18,5 +20,17 @@ namespace SixLabors.ImageSharp
: base(errorMessage) : base(errorMessage)
{ {
} }
/// <summary>
/// Initializes a new instance of the <see cref="InvalidImageContentException"/> class with the name of the
/// parameter that causes this exception.
/// </summary>
/// <param name="errorMessage">The error message that explains the reason for this exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic)
/// if no inner exception is specified.</param>
public InvalidImageContentException(string errorMessage, Exception innerException)
: base(errorMessage, innerException)
{
}
} }
} }

4
src/ImageSharp/Formats/Bmp/BmpDecoder.cs

@ -43,9 +43,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
{ {
Size dims = decoder.Dimensions; Size dims = decoder.Dimensions;
// TODO: use InvalidImageContentException here, if we decide to define it throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}. This error can happen for very large RLE bitmaps, which are not supported.", ex);
// https://github.com/SixLabors/ImageSharp/issues/1110
throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}. This error can happen for very large RLE bitmaps, which are not supported.", ex);
} }
} }

7
src/ImageSharp/Formats/Gif/GifDecoder.cs

@ -38,9 +38,10 @@ namespace SixLabors.ImageSharp.Formats.Gif
{ {
Size dims = decoder.Dimensions; Size dims = decoder.Dimensions;
// TODO: use InvalidImageContentException here, if we decide to define it GifThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
// https://github.com/SixLabors/ImageSharp/issues/1110
throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex); // Not reachable, as the previous statement will throw a exception.
return null;
} }
} }

8
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -6,7 +6,7 @@ using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Decodes the stream to the image. /// Decodes the stream to the image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image data. </param> /// <param name="stream">The stream containing image data.</param>
/// <returns>The decoded image</returns> /// <returns>The decoded image</returns>
public Image<TPixel> Decode<TPixel>(Stream stream) public Image<TPixel> Decode<TPixel>(Stream stream)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
@ -241,6 +241,10 @@ namespace SixLabors.ImageSharp.Formats.Gif
this.stream.Read(this.buffer, 0, 9); this.stream.Read(this.buffer, 0, 9);
this.imageDescriptor = GifImageDescriptor.Parse(this.buffer); this.imageDescriptor = GifImageDescriptor.Parse(this.buffer);
if (this.imageDescriptor.Height == 0 || this.imageDescriptor.Width == 0)
{
GifThrowHelper.ThrowInvalidImageContentException("Width or height should not be 0");
}
} }
/// <summary> /// <summary>

12
src/ImageSharp/Formats/Gif/GifThrowHelper.cs

@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Formats.Gif namespace SixLabors.ImageSharp.Formats.Gif
@ -11,8 +12,17 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Cold path optimization for throwing <see cref="InvalidImageContentException"/>'s /// Cold path optimization for throwing <see cref="InvalidImageContentException"/>'s
/// </summary> /// </summary>
/// <param name="errorMessage">The error message for the exception.</param> /// <param name="errorMessage">The error message for the exception.</param>
[MethodImpl(MethodImplOptions.NoInlining)] [MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage) public static void ThrowInvalidImageContentException(string errorMessage)
=> throw new InvalidImageContentException(errorMessage); => throw new InvalidImageContentException(errorMessage);
/// <summary>
/// Cold path optimization for throwing <see cref="InvalidImageContentException"/>'s.
/// </summary>
/// <param name="errorMessage">The error message for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// if no inner exception is specified.</param>
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException) => throw new InvalidImageContentException(errorMessage, innerException);
} }
} }

8
src/ImageSharp/Formats/Gif/README.md

@ -1,4 +1,6 @@
Encoder/Decoder adapted and extended from: Encoder/Decoder adapted and extended from:
https://github.com/yufeih/Nine.Imaging/ - [Nine.Imaging](https://github.com/yufeih/Nine.Imaging/)
https://imagetools.codeplex.com/ - [imagetools.codeplex](https://imagetools.codeplex.com/)
A useful set of gif test images can be found at [pygif](https://github.com/robert-ancell/pygif/tree/master/test-suite)

7
src/ImageSharp/Formats/Jpeg/JpegDecoder.cs

@ -32,9 +32,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
{ {
(int w, int h) = (decoder.ImageWidth, decoder.ImageHeight); (int w, int h) = (decoder.ImageWidth, decoder.ImageHeight);
// TODO: use InvalidImageContentException here, if we decide to define it JpegThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {w}x{h}.", ex);
// https://github.com/SixLabors/ImageSharp/issues/1110
throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {w}x{h}.", ex); // Not reachable, as the previous statement will throw a exception.
return null;
} }
} }

9
src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs

@ -15,6 +15,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
[MethodImpl(InliningOptions.ColdPath)] [MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage); public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);
/// <summary>
/// Cold path optimization for throwing <see cref="InvalidImageContentException"/>'s.
/// </summary>
/// <param name="errorMessage">The error message for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// if no inner exception is specified.</param>
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException) => throw new InvalidImageContentException(errorMessage, innerException);
/// <summary> /// <summary>
/// Cold path optimization for throwing <see cref="NotImplementedException"/>'s /// Cold path optimization for throwing <see cref="NotImplementedException"/>'s
/// </summary> /// </summary>

7
src/ImageSharp/Formats/Png/PngDecoder.cs

@ -54,9 +54,10 @@ namespace SixLabors.ImageSharp.Formats.Png
{ {
Size dims = decoder.Dimensions; Size dims = decoder.Dimensions;
// TODO: use InvalidImageContentException here, if we decide to define it PngThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
// https://github.com/SixLabors/ImageSharp/issues/1110
throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex); // Not reachable, as the previous statement will throw a exception.
return null;
} }
} }

24
src/ImageSharp/Formats/Png/PngMetadata.cs

@ -91,34 +91,12 @@ namespace SixLabors.ImageSharp.Formats.Png
public bool HasTransparency { get; set; } public bool HasTransparency { get; set; }
/// <summary> /// <summary>
/// Gets or sets the collection of text data stored within the iTXt, tEXt, and zTXt chunks. /// Gets or sets the collection of text data stored within the iTXt, tEXt, and zTXt chunks.
/// Used for conveying textual information associated with the image. /// Used for conveying textual information associated with the image.
/// </summary> /// </summary>
public IList<PngTextData> TextData { get; set; } = new List<PngTextData>(); public IList<PngTextData> TextData { get; set; } = new List<PngTextData>();
/// <summary>
/// Gets the list of png text properties for storing meta information about this image.
/// </summary>
public IList<PngTextData> PngTextProperties { get; } = new List<PngTextData>();
/// <inheritdoc/> /// <inheritdoc/>
public IDeepCloneable DeepClone() => new PngMetadata(this); public IDeepCloneable DeepClone() => new PngMetadata(this);
internal bool TryGetPngTextProperty(string keyword, out PngTextData result)
{
for (int i = 0; i < this.TextData.Count; i++)
{
if (this.TextData[i].Keyword == keyword)
{
result = this.TextData[i];
return true;
}
}
result = default;
return false;
}
} }
} }

4
src/ImageSharp/Formats/Png/PngThrowHelper.cs

@ -11,6 +11,10 @@ namespace SixLabors.ImageSharp.Formats.Png
/// </summary> /// </summary>
internal static class PngThrowHelper internal static class PngThrowHelper
{ {
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException)
=> throw new InvalidImageContentException(errorMessage, innerException);
[MethodImpl(InliningOptions.ColdPath)] [MethodImpl(InliningOptions.ColdPath)]
public static void ThrowNoHeader() => throw new InvalidImageContentException("PNG Image does not contain a header chunk"); public static void ThrowNoHeader() => throw new InvalidImageContentException("PNG Image does not contain a header chunk");

7
src/ImageSharp/Formats/Tga/TgaDecoder.cs

@ -28,9 +28,10 @@ namespace SixLabors.ImageSharp.Formats.Tga
{ {
Size dims = decoder.Dimensions; Size dims = decoder.Dimensions;
// TODO: use InvalidImageContentException here, if we decide to define it TgaThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
// https://github.com/SixLabors/ImageSharp/issues/1110
throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex); // Not reachable, as the previous statement will throw a exception.
return null;
} }
} }

14
src/ImageSharp/Formats/Tga/TgaThrowHelper.cs

@ -12,15 +12,25 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// Cold path optimization for throwing <see cref="ImageFormatException"/>'s /// Cold path optimization for throwing <see cref="ImageFormatException"/>'s
/// </summary> /// </summary>
/// <param name="errorMessage">The error message for the exception.</param> /// <param name="errorMessage">The error message for the exception.</param>
[MethodImpl(MethodImplOptions.NoInlining)] [MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage) public static void ThrowInvalidImageContentException(string errorMessage)
=> throw new InvalidImageContentException(errorMessage); => throw new InvalidImageContentException(errorMessage);
/// <summary>
/// Cold path optimization for throwing <see cref="ImageFormatException"/>'s
/// </summary>
/// <param name="errorMessage">The error message for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// if no inner exception is specified.</param>
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException)
=> throw new InvalidImageContentException(errorMessage, innerException);
/// <summary> /// <summary>
/// Cold path optimization for throwing <see cref="NotSupportedException"/>'s /// Cold path optimization for throwing <see cref="NotSupportedException"/>'s
/// </summary> /// </summary>
/// <param name="errorMessage">The error message for the exception.</param> /// <param name="errorMessage">The error message for the exception.</param>
[MethodImpl(MethodImplOptions.NoInlining)] [MethodImpl(InliningOptions.ColdPath)]
public static void ThrowNotSupportedException(string errorMessage) public static void ThrowNotSupportedException(string errorMessage)
=> throw new NotSupportedException(errorMessage); => throw new NotSupportedException(errorMessage);
} }

2
tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs

@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10); provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10);
ImageFormatException ex = Assert.Throws<ImageFormatException>(() => provider.GetImage(BmpDecoder)); InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(BmpDecoder));
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException); Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
} }

84
tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs

@ -2,11 +2,9 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using Microsoft.DotNet.RemoteExecutor; using Microsoft.DotNet.RemoteExecutor;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata;
@ -30,32 +28,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
TestImages.Gif.Giphy, TestImages.Gif.Kumin TestImages.Gif.Giphy, TestImages.Gif.Kumin
}; };
public static readonly string[] BasicVerificationFiles =
{
TestImages.Gif.Cheers,
TestImages.Gif.Rings,
// previously DecodeBadApplicationExtensionLength:
TestImages.Gif.Issues.BadAppExtLength,
TestImages.Gif.Issues.BadAppExtLength_2,
// previously DecodeBadDescriptorDimensionsLength:
TestImages.Gif.Issues.BadDescriptorWidth
};
private static readonly Dictionary<string, int> BasicVerificationFrameCount =
new Dictionary<string, int>
{
[TestImages.Gif.Cheers] = 93,
[TestImages.Gif.Issues.BadDescriptorWidth] = 36,
};
public static readonly string[] BadAppExtFiles =
{
TestImages.Gif.Issues.BadAppExtLength,
TestImages.Gif.Issues.BadAppExtLength_2
};
[Theory] [Theory]
[WithFileCollection(nameof(MultiFrameTestFiles), PixelTypes.Rgba32)] [WithFileCollection(nameof(MultiFrameTestFiles), PixelTypes.Rgba32)]
public void Decode_VerifyAllFrames<TPixel>(TestImageProvider<TPixel> provider) public void Decode_VerifyAllFrames<TPixel>(TestImageProvider<TPixel> provider)
@ -100,15 +72,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
} }
[Theory] [Theory]
[WithFileCollection(nameof(BasicVerificationFiles), PixelTypes.Rgba32)] [WithFile(TestImages.Gif.Cheers, PixelTypes.Rgba32, 93)]
public void Decode_VerifyRootFrameAndFrameCount<TPixel>(TestImageProvider<TPixel> provider) [WithFile(TestImages.Gif.Rings, PixelTypes.Rgba32, 1)]
[WithFile(TestImages.Gif.Issues.BadDescriptorWidth, PixelTypes.Rgba32, 36)]
public void Decode_VerifyRootFrameAndFrameCount<TPixel>(TestImageProvider<TPixel> provider, int expectedFrameCount)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
if (!BasicVerificationFrameCount.TryGetValue(provider.SourceFileOrDescription, out int expectedFrameCount))
{
expectedFrameCount = 1;
}
using (Image<TPixel> image = provider.GetImage()) using (Image<TPixel> image = provider.GetImage())
{ {
Assert.Equal(expectedFrameCount, image.Frames.Count); Assert.Equal(expectedFrameCount, image.Frames.Count);
@ -153,6 +122,35 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
} }
} }
[Theory]
[WithFile(TestImages.Gif.ZeroSize, PixelTypes.Rgba32)]
[WithFile(TestImages.Gif.ZeroWidth, PixelTypes.Rgba32)]
[WithFile(TestImages.Gif.ZeroHeight, PixelTypes.Rgba32)]
public void Decode_WithInvalidDimensions_DoesThrowException<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
System.Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(GifDecoder);
});
Assert.NotNull(ex);
Assert.Contains("Width or height should not be 0", ex.Message);
}
[Theory]
[WithFile(TestImages.Gif.MaxWidth, PixelTypes.Rgba32, 65535, 1)]
[WithFile(TestImages.Gif.MaxHeight, PixelTypes.Rgba32, 1, 65535)]
public void Decode_WithMaxDimensions_Works<TPixel>(TestImageProvider<TPixel> provider, int expectedWidth, int expectedHeight)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(GifDecoder))
{
Assert.Equal(expectedWidth, image.Width);
Assert.Equal(expectedHeight, image.Height);
}
}
[Fact] [Fact]
public void CanDecodeIntermingledImages() public void CanDecodeIntermingledImages()
{ {
@ -172,6 +170,20 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
} }
} }
// https://github.com/SixLabors/ImageSharp/issues/405
[Theory]
[WithFile(TestImages.Gif.Issues.BadAppExtLength, PixelTypes.Rgba32)]
[WithFile(TestImages.Gif.Issues.BadAppExtLength_2, PixelTypes.Rgba32)]
public void Issue405_BadApplicationExtensionBlockLength<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.DebugSave(provider);
image.CompareFirstFrameToReferenceOutput(ImageComparer.Exact, provider);
}
}
[Theory] [Theory]
[WithFile(TestImages.Gif.Giphy, PixelTypes.Rgba32)] [WithFile(TestImages.Gif.Giphy, PixelTypes.Rgba32)]
[WithFile(TestImages.Gif.Kumin, PixelTypes.Rgba32)] [WithFile(TestImages.Gif.Kumin, PixelTypes.Rgba32)]
@ -179,7 +191,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10); provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10);
ImageFormatException ex = Assert.Throws<ImageFormatException>(() => provider.GetImage(GifDecoder)); InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(GifDecoder));
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException); Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
} }

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

@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
provider.LimitAllocatorBufferCapacity().InBytesSqrt(10); provider.LimitAllocatorBufferCapacity().InBytesSqrt(10);
ImageFormatException ex = Assert.Throws<ImageFormatException>(() => provider.GetImage(JpegDecoder)); InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(JpegDecoder));
this.Output.WriteLine(ex.Message); this.Output.WriteLine(ex.Message);
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException); Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
} }

2
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -397,7 +397,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10); provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10);
ImageFormatException ex = Assert.Throws<ImageFormatException>(() => provider.GetImage(PngDecoder)); InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(PngDecoder));
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException); Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
} }

2
tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs

@ -740,7 +740,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tga
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10); provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10);
ImageFormatException ex = Assert.Throws<ImageFormatException>(() => provider.GetImage(TgaDecoder)); InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(TgaDecoder));
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException); Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
} }

7
tests/ImageSharp.Tests/TestImages.cs

@ -397,6 +397,13 @@ namespace SixLabors.ImageSharp.Tests
public const string Ratio1x4 = "Gif/base_1x4.gif"; public const string Ratio1x4 = "Gif/base_1x4.gif";
public const string LargeComment = "Gif/large_comment.gif"; public const string LargeComment = "Gif/large_comment.gif";
// Test images from https://github.com/robert-ancell/pygif/tree/master/test-suite
public const string ZeroSize = "Gif/image-zero-size.gif";
public const string ZeroHeight = "Gif/image-zero-height.gif";
public const string ZeroWidth = "Gif/image-zero-width.gif";
public const string MaxWidth = "Gif/max-width.gif";
public const string MaxHeight = "Gif/max-height.gif";
public static class Issues public static class Issues
{ {
public const string BadAppExtLength = "Gif/issues/issue405_badappextlength252.gif"; public const string BadAppExtLength = "Gif/issues/issue405_badappextlength252.gif";

2
tests/Images/External

@ -1 +1 @@
Subproject commit 6fdc6d19b101dc1c00a297d3e92257df60c413d0 Subproject commit 0d1f91e2fe1491f6dc2c137a8ea20460fde4404c

3
tests/Images/Input/Gif/image-zero-height.gif

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:37248eeb127e43bb002f621409cb6dabaa6b58a62612d26009722c4ae7c83dd6
size 30

3
tests/Images/Input/Gif/image-zero-size.gif

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:518aa6f50b003b76e8b65e798d2a37b6dad7dade96d0a7db73da88eec07efe0e
size 30

3
tests/Images/Input/Gif/image-zero-width.gif

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4cde31fe4bcc863f70f66c5a57d62647b11512920328fc5658399ef566ebebef
size 30

3
tests/Images/Input/Gif/max-height.gif

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8853634077f425f4b2077f4ca0c986e4ac0e549a8601859b0578a3ccbdbdd5d4
size 405

3
tests/Images/Input/Gif/max-width.gif

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