-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add initial AssemblyNameInfo Fuzzer * fix the first bug that it has discovered
- Loading branch information
1 parent
4df1b9a
commit ac663e4
Showing
4 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/libraries/Fuzzing/DotnetFuzzing/Fuzzers/AssemblyNameInfoFuzzer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Buffers; | ||
using System.Reflection.Metadata; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace DotnetFuzzing.Fuzzers | ||
{ | ||
internal sealed class AssemblyNameInfoFuzzer : IFuzzer | ||
{ | ||
public string[] TargetAssemblies => ["System.Reflection.Metadata"]; | ||
|
||
public string[] TargetCoreLibPrefixes => []; | ||
|
||
public void FuzzTarget(ReadOnlySpan<byte> bytes) | ||
{ | ||
ReadOnlySpan<char> chars = MemoryMarshal.Cast<byte, char>(bytes); | ||
|
||
using PooledBoundedMemory<char> inputPoisonedBefore = PooledBoundedMemory<char>.Rent(chars, PoisonPagePlacement.Before); | ||
using PooledBoundedMemory<char> inputPoisonedAfter = PooledBoundedMemory<char>.Rent(chars, PoisonPagePlacement.After); | ||
|
||
Test(inputPoisonedBefore); | ||
Test(inputPoisonedAfter); | ||
} | ||
|
||
private static void Test(PooledBoundedMemory<char> inputPoisoned) | ||
{ | ||
bool shouldSucceed = AssemblyNameInfo.TryParse(inputPoisoned.Span, out _); | ||
|
||
try | ||
{ | ||
AssemblyNameInfo.Parse(inputPoisoned.Span); | ||
} | ||
catch (ArgumentException) | ||
{ | ||
Assert.Equal(false, shouldSucceed); | ||
return; | ||
} | ||
|
||
Assert.Equal(true, shouldSucceed); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters