From 731abc7aaafbbae25b9c2ca824f18c03f3e20280 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Wed, 24 Aug 2022 13:18:41 +0200 Subject: [PATCH] Add encode test for width and size > 65k --- .../Formats/Bmp/BmpEncoderTests.cs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs index dd59fb279..b28e2122a 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System; using System.IO; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Bmp; @@ -20,6 +21,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp [Trait("Format", "Bmp")] public class BmpEncoderTests { + private static BmpEncoder BmpEncoder => new(); + public static readonly TheoryData BitsPerPixel = new() { @@ -50,14 +53,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp [MemberData(nameof(RatioFiles))] public void Encode_PreserveRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) { - var options = new BmpEncoder(); - var testFile = TestFile.Create(imagePath); using (Image input = testFile.CreateRgba32Image()) { using (var memStream = new MemoryStream()) { - input.Save(memStream, options); + input.Save(memStream, BmpEncoder); memStream.Position = 0; using (var output = Image.Load(memStream)) @@ -75,14 +76,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp [MemberData(nameof(BmpBitsPerPixelFiles))] public void Encode_PreserveBitsPerPixel(string imagePath, BmpBitsPerPixel bmpBitsPerPixel) { - var options = new BmpEncoder(); - var testFile = TestFile.Create(imagePath); using (Image input = testFile.CreateRgba32Image()) { using (var memStream = new MemoryStream()) { - input.Save(memStream, options); + input.Save(memStream, BmpEncoder); memStream.Position = 0; using (var output = Image.Load(memStream)) @@ -328,6 +327,21 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp } } + [Theory] + [InlineData(1, 66535)] + [InlineData(66535, 1)] + public void Encode_WorksWithSizeGreaterThen65k(int width, int height) + { + Exception exception = Record.Exception(() => + { + using Image image = new Image(width, height); + using var memStream = new MemoryStream(); + image.Save(memStream, BmpEncoder); + }); + + Assert.Null(exception); + } + [Theory] [WithFile(Car, PixelTypes.Rgba32, BmpBitsPerPixel.Pixel32)] [WithFile(V5Header, PixelTypes.Rgba32, BmpBitsPerPixel.Pixel32)]