Browse Source

relaxed bmp dimensions validation

pull/2192/head
smorokin 4 years ago
committed by GitHub
parent
commit
939607c459
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs

15
src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs

@ -545,13 +545,22 @@ namespace SixLabors.ImageSharp.Formats.Bmp
internal void VerifyDimensions() internal void VerifyDimensions()
{ {
const int MaximumBmpDimension = 65535; const int MaximumBmpDimension = 2147483647; // 2**31 - 1, since width & height are int32
if (this.Width > MaximumBmpDimension || this.Height > MaximumBmpDimension) if (this.Width > MaximumBmpDimension || this.Height > MaximumBmpDimension)
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
$"The input bmp '{this.Width}x{this.Height}' is " $"The input bmp '{this.Width}x{this.Height}' has a width or height "
+ $"bigger then the max allowed size '{MaximumBmpDimension}x{MaximumBmpDimension}'"); + $"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;
if (size > MaximumBmpSize)
{
throw new InvalidOperationException(
$"The input bmp '{this.Width}x{this.Height}' has a size {size}"
+ $"bigger then the max allowed '{MaximumBmpSize}'");
} }
} }
} }

Loading…
Cancel
Save