Skip to content

Commit 8d7d413

Browse files
Merge pull request #2192 from smorokin/patch-1
Relaxed bmp dimensions validation
2 parents 6e065fa + 028526f commit 8d7d413

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,8 +1471,6 @@ private int ReadImageHeaders(BufferedReadStream stream, out bool inverted, out b
14711471
}
14721472
}
14731473

1474-
this.infoHeader.VerifyDimensions();
1475-
14761474
int skipAmount = this.fileHeader.Offset - (int)this.stream.Position;
14771475
if ((skipAmount + (int)this.stream.Position) > this.stream.Length)
14781476
{

src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -542,17 +542,5 @@ public void WriteV5Header(Span<byte> buffer)
542542

543543
dest = this;
544544
}
545-
546-
internal void VerifyDimensions()
547-
{
548-
const int MaximumBmpDimension = 65535;
549-
550-
if (this.Width > MaximumBmpDimension || this.Height > MaximumBmpDimension)
551-
{
552-
throw new InvalidOperationException(
553-
$"The input bmp '{this.Width}x{this.Height}' is "
554-
+ $"bigger then the max allowed size '{MaximumBmpDimension}x{MaximumBmpDimension}'");
555-
}
556-
}
557545
}
558546
}

tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
using System;
45
using System.IO;
56
using SixLabors.ImageSharp.Formats;
67
using SixLabors.ImageSharp.Formats.Bmp;
@@ -350,6 +351,21 @@ public void Encode_PreservesColorProfile<TPixel>(TestImageProvider<TPixel> provi
350351
Assert.Equal(expectedProfileBytes, actualProfileBytes);
351352
}
352353

354+
[Theory]
355+
[InlineData(1, 66535)]
356+
[InlineData(66535, 1)]
357+
public void Encode_WorksWithSizeGreaterThen65k(int width, int height)
358+
{
359+
Exception exception = Record.Exception(() =>
360+
{
361+
using Image image = new Image<Rgba32>(width, height);
362+
using var memStream = new MemoryStream();
363+
image.Save(memStream, BmpEncoder);
364+
});
365+
366+
Assert.Null(exception);
367+
}
368+
353369
[Theory]
354370
[WithFile(Car, PixelTypes.Rgba32, BmpBitsPerPixel.Pixel32)]
355371
[WithFile(V5Header, PixelTypes.Rgba32, BmpBitsPerPixel.Pixel32)]

0 commit comments

Comments
 (0)