Browse Source

fix BMP dimension check

af/merge-core
Anton Firszov 8 years ago
parent
commit
1039c2c8f9
  1. 8
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  2. 12
      src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs

8
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();
}
}
}

12
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}'");
}
}
}
}
Loading…
Cancel
Save