diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 4812b550d..0b4b98749 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -1472,8 +1472,6 @@ namespace SixLabors.ImageSharp.Formats.Bmp } } - this.infoHeader.VerifyDimensions(); - int skipAmount = this.fileHeader.Offset - (int)this.stream.Position; if ((skipAmount + (int)this.stream.Position) > this.stream.Length) { diff --git a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs index e7536ccac..ac3bc9d3c 100644 --- a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs +++ b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs @@ -541,17 +541,5 @@ namespace SixLabors.ImageSharp.Formats.Bmp dest = this; } - - internal void VerifyDimensions() - { - const int maximumBmpDimension = 65535; - - if (this.Width > maximumBmpDimension || this.Height > maximumBmpDimension) - { - throw new InvalidOperationException( - $"The input bmp '{this.Width}x{this.Height}' is " - + $"bigger then the max allowed size '{maximumBmpDimension}x{maximumBmpDimension}'"); - } - } } } diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs index bb88cc462..3bef0dbca 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; @@ -350,6 +351,21 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp Assert.Equal(expectedProfileBytes, actualProfileBytes); } + [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)]