Browse Source

Merge pull request #3134 from SixLabors/js/fix-pbm-dcoder

Validate PBM max pixel value
main
James Jackson-South 5 days ago
committed by GitHub
parent
commit
f6d369d86a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs
  2. 13
      tests/ImageSharp.Tests/Formats/Pbm/PbmDecoderTests.cs

5
src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs

@ -155,6 +155,11 @@ internal sealed class PbmDecoderCore : ImageDecoderCore
ThrowPrematureEof();
}
if (this.maxPixelValue <= 0 || this.maxPixelValue >= 65536)
{
throw new InvalidImageContentException("Invalid max pixel value.");
}
if (this.maxPixelValue > 255)
{
this.componentType = PbmComponentType.Short;

13
tests/ImageSharp.Tests/Formats/Pbm/PbmDecoderTests.cs

@ -123,6 +123,19 @@ public class PbmDecoderTests
appendPixelTypeToFileName: false);
}
[Theory]
[InlineData("P2")]
[InlineData("P3")]
[InlineData("P5")]
[InlineData("P6")]
public void Decode_MaxPixelValueZero_ThrowsInvalidImageContentException(string magic)
{
byte[] bytes = Encoding.ASCII.GetBytes($"{magic} 1 1 0\n0");
using MemoryStream stream = new(bytes);
Assert.Throws<InvalidImageContentException>(() => Image.Load<Rgba32>(stream));
}
[Fact]
public void PlainText_PrematureEof()
{

Loading…
Cancel
Save