Skip to content

Commit ef5fe79

Browse files
Prevent crafted DOS attack.
1 parent 900e9d0 commit ef5fe79

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/ImageSharp/Formats/Pbm/BufferedReadStreamExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void SkipWhitespaceAndComments(this BufferedReadStream stream)
2828
{
2929
innerValue = stream.ReadByte();
3030
}
31-
while (innerValue != 0x0a);
31+
while (innerValue is not 0x0a and not -0x1);
3232

3333
// Continue searching for whitespace.
3434
val = innerValue;

tests/ImageSharp.Tests/Formats/Pbm/PbmMetadataTests.cs

Lines changed: 11 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 SixLabors.ImageSharp.Formats;
45
using SixLabors.ImageSharp.Formats.Pbm;
56
using static SixLabors.ImageSharp.Tests.TestImages.Pbm;
67

@@ -80,4 +81,14 @@ public void Identify_DetectsCorrectComponentType(string imagePath, PbmComponentT
8081
Assert.NotNull(bitmapMetadata);
8182
Assert.Equal(expectedComponentType, bitmapMetadata.ComponentType);
8283
}
84+
85+
[Fact]
86+
public void Identify_HandlesCraftedDenialOfServiceString()
87+
{
88+
byte[] bytes = Convert.FromBase64String("UDEjWAAACQAAAAA=");
89+
ImageInfo info = Image.Identify(bytes);
90+
Assert.Equal(default, info.Size);
91+
Configuration.Default.ImageFormatsManager.TryFindFormatByFileExtension("pbm", out IImageFormat format);
92+
Assert.Equal(format!, info.Metadata.DecodedImageFormat);
93+
}
8394
}

0 commit comments

Comments
 (0)