Browse Source

Re-enable DegenerateMemoryRequest test, fix Exception to be ImageFormatException

af/octree-no-pixelmap
Brian Popow 6 years ago
parent
commit
4ef1852fac
  1. 17
      src/ImageSharp/Formats/Tga/TgaDecoder.cs
  2. 2
      src/ImageSharp/Formats/Tga/TgaDecoderCore.cs
  3. 3
      tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs

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

@ -1,7 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.IO;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Tga
@ -17,7 +19,20 @@ namespace SixLabors.ImageSharp.Formats.Tga
{
Guard.NotNull(stream, nameof(stream));
return new TgaDecoderCore(configuration, this).Decode<TPixel>(stream);
var decoder = new TgaDecoderCore(configuration, this);
try
{
return decoder.Decode<TPixel>(stream);
}
catch (InvalidMemoryOperationException ex)
{
Size dims = decoder.Dimensions;
// TODO: use InvalidImageContentException here, if we decide to define it
// 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);
}
}
/// <inheritdoc />

2
src/ImageSharp/Formats/Tga/TgaDecoderCore.cs

@ -61,6 +61,8 @@ namespace SixLabors.ImageSharp.Formats.Tga
this.options = options;
}
public Size Dimensions => new Size(this.fileHeader.Width, this.fileHeader.Height);
/// <summary>
/// Decodes the image from the specified stream.
/// </summary>

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

@ -196,8 +196,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tga
}
}
// TODO: A InvalidMemoryOperationException is thrown here, review the thrown exception.
[Theory(Skip = "Review Exception")]
[Theory]
[WithFile(Bit16, PixelTypes.Rgba32)]
[WithFile(Bit24, PixelTypes.Rgba32)]
[WithFile(Bit32, PixelTypes.Rgba32)]

Loading…
Cancel
Save