Browse Source

Add tests for bmp and tga header to throw UnknownImageFormatException when there is insufficient data

pull/1026/head
Brian Popow 6 years ago
parent
commit
b1e8202c28
  1. 21
      tests/ImageSharp.Tests/Formats/Bmp/BmpFileHeaderTests.cs
  2. 29
      tests/ImageSharp.Tests/Formats/Tga/TgaFileHeaderTests.cs

21
tests/ImageSharp.Tests/Formats/Bmp/BmpFileHeaderTests.cs

@ -1,4 +1,10 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.IO;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Bmp;
using Xunit;
@ -6,6 +12,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
{
public class BmpFileHeaderTests
{
private static readonly byte[] Data = BitConverter.GetBytes(BmpConstants.TypeMarkers.Bitmap);
private MemoryStream Stream { get; } = new MemoryStream(Data);
[Fact]
public void TestWrite()
{
@ -17,5 +27,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
Assert.Equal("AQACAAAAAwAAAAQAAAA=", Convert.ToBase64String(buffer));
}
[Fact]
public void ImageLoad_WithoutEnoughData_Throws_UnknownImageFormatException()
{
Assert.Throws<UnknownImageFormatException>(() =>
{
using (Image.Load(Configuration.Default, this.Stream, out IImageFormat _))
{
}
});
}
}
}

29
tests/ImageSharp.Tests/Formats/Tga/TgaFileHeaderTests.cs

@ -0,0 +1,29 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using SixLabors.ImageSharp.Formats;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tga
{
public class TgaFileHeaderTests
{
private static readonly byte[] Data = { 0, 0, 0 };
private MemoryStream Stream { get; } = new MemoryStream(Data);
[Fact]
public void ImageLoad_WithoutEnoughData_Throws_UnknownImageFormatException()
{
Assert.Throws<UnknownImageFormatException>(() =>
{
using (Image.Load(Configuration.Default, this.Stream, out IImageFormat _))
{
}
});
}
}
}
Loading…
Cancel
Save