diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index f5121a1a3..dd092e643 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -580,13 +580,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp this.stream.Read(palette, 0, colorMapSize); } - // TODO: ReSharper tells this expression is always false, looks like he's pretty right about it: - if (this.infoHeader.Width > int.MaxValue || this.infoHeader.Height > int.MaxValue) - { - throw new ArgumentOutOfRangeException( - $"The input bmp '{this.infoHeader.Width}x{this.infoHeader.Height}' is " - + $"bigger then the max allowed size '{int.MaxValue}x{int.MaxValue}'"); - } + this.infoHeader.VerifyDimensions(); } } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs index a088a9b13..a70716a85 100644 --- a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs +++ b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs @@ -157,5 +157,17 @@ 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}'"); + } + } } } \ No newline at end of file