Skip to content

Commit

Permalink
Backport #2501
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Aug 10, 2023
1 parent 71d5316 commit e0d14b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Pbm/BufferedReadStreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void SkipWhitespaceAndComments(this BufferedReadStream stream)
{
innerValue = stream.ReadByte();
}
while (innerValue != 0x0a);
while (innerValue is not 0x0a and not -0x1);

// Continue searching for whitespace.
val = innerValue;
Expand Down
12 changes: 12 additions & 0 deletions tests/ImageSharp.Tests/Formats/Pbm/PbmMetadataTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System;
using System.IO;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Pbm;

using Xunit;
Expand Down Expand Up @@ -82,5 +84,15 @@ public void Identify_DetectsCorrectComponentType(string imagePath, PbmComponentT
Assert.NotNull(bitmapMetadata);
Assert.Equal(expectedComponentType, bitmapMetadata.ComponentType);
}

[Fact]
public void Identify_HandlesCraftedDenialOfServiceString()
{
byte[] bytes = Convert.FromBase64String("UDEjWAAACQAAAAA=");
IImageInfo info = Image.Identify(bytes);
Assert.Equal(default, info.Size());
IImageFormat format = Configuration.Default.ImageFormatsManager.FindFormatByFileExtension("pbm");
Assert.Equal("PBM", format.Name);
}
}
}

0 comments on commit e0d14b1

Please sign in to comment.