Browse Source

Merge branch 'main' into js/remove-obsolete-code

pull/2189/head
James Jackson-South 3 years ago
committed by GitHub
parent
commit
145dc9ef2b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  2. 12
      src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs
  3. 16
      tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs

2
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)
{

12
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}'");
}
}
}
}

16
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<Rgba32>(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)]

Loading…
Cancel
Save