diff --git a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs index c1d7d223f8..ca52e4db13 100644 --- a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs +++ b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs @@ -66,6 +66,16 @@ namespace SixLabors.ImageSharp.Formats.Bmp /// public const int HeaderSizeSize = 4; + /// + /// Maximum dimensions of a bitmap with or height: 2**31 - 1, since width and height are int32 + /// + private const int MaximumBmpDimension = 2147483647; + + /// + /// Maximum size of a bitmap width * height: 2**32, since size is uint32. + /// + private const long MaximumBmpSize = 4294967296; + public BmpInfoHeader( int headerSize, int width, @@ -545,8 +555,6 @@ namespace SixLabors.ImageSharp.Formats.Bmp internal void VerifyDimensions() { - const int MaximumBmpDimension = 2147483647; // 2**31 - 1, since width & height are int32 - if (this.Width > MaximumBmpDimension || this.Height > MaximumBmpDimension) { throw new InvalidOperationException( @@ -554,8 +562,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp + $"bigger then the max allowed '{MaximumBmpDimension}'"); } - const long MaximumBmpSize = 4294967296; // 2**32, since size is uint32 - const long size = (long)this.Width * (long)this.Height; + long size = this.Width * this.Height; if (size > MaximumBmpSize) { throw new InvalidOperationException(