Skip to content

Commit

Permalink
Reference System.Formats.Nrbf project directly, remove catch blocks t…
Browse files Browse the repository at this point in the history
…hat not needed anymore with the fix
  • Loading branch information
buyaa-n committed Sep 5, 2024
1 parent b89443d commit 98b0728
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/libraries/Fuzzing/DotnetFuzzing/DotnetFuzzing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

<ItemGroup>
<PackageReference Include="SharpFuzz" Version="2.1.1" />
<PackageReference Include="System.Formats.Nrbf" Version="9.0.0-preview.7.24405.7" />
</ItemGroup>

<ItemGroup>
Expand All @@ -31,4 +30,8 @@
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\System.Formats.Nrbf\src\System.Formats.Nrbf.csproj" />
</ItemGroup>

</Project>
26 changes: 15 additions & 11 deletions src/libraries/Fuzzing/DotnetFuzzing/Fuzzers/NrbfDecoderFuzzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ internal sealed class NrbfDecoderFuzzer : IFuzzer

public void FuzzTarget(ReadOnlySpan<byte> bytes)
{
using PooledBoundedMemory<byte> inputPoisoned = PooledBoundedMemory<byte>.Rent(bytes, PoisonPagePlacement.After);
using MemoryStream stream = new MemoryStream(inputPoisoned.Memory.ToArray());
using PooledBoundedMemory<byte> inputPoisonedAfter = PooledBoundedMemory<byte>.Rent(bytes, PoisonPagePlacement.After);
using PooledBoundedMemory<byte> inputPoisonedBefore = PooledBoundedMemory<byte>.Rent(bytes, PoisonPagePlacement.Before);
using MemoryStream streamAfter = new MemoryStream(inputPoisonedAfter.Memory.ToArray());
using MemoryStream streamBefore = new MemoryStream(inputPoisonedBefore.Memory.ToArray());

if (NrbfDecoder.StartsWithPayloadHeader(inputPoisoned.Span))
Test(inputPoisonedAfter.Span, streamAfter);
Test(inputPoisonedBefore.Span, streamBefore);
}

private static void Test(Span<byte> testSpan, MemoryStream stream)
{
if (NrbfDecoder.StartsWithPayloadHeader(testSpan))
{
try
{
Expand Down Expand Up @@ -52,15 +60,14 @@ public void FuzzTarget(ReadOnlySpan<byte> bytes)
case SerializationRecordType.ClassWithId:
case SerializationRecordType.ClassWithMembersAndTypes:
case SerializationRecordType.SystemClassWithMembersAndTypes:
{
ClassRecord classRecord = (ClassRecord)record;
Assert.NotNull(classRecord.TypeName);

foreach (string name in classRecord.MemberNames)
{
Assert.Equal(true, classRecord.HasMember(name));
}
} break;
break;
case SerializationRecordType.MemberPrimitiveTyped:
PrimitiveTypeRecord primitiveType = (PrimitiveTypeRecord)record;
Assert.NotNull(primitiveType.Value);
Expand All @@ -72,7 +79,7 @@ public void FuzzTarget(ReadOnlySpan<byte> bytes)
case SerializationRecordType.ObjectNull:
case SerializationRecordType.ObjectNullMultiple:
case SerializationRecordType.ObjectNullMultiple256:
Assert.Equal(default, record.Id);
// Assert.Equal(default, record.Id);
break;
case SerializationRecordType.MessageEnd:
case SerializationRecordType.SerializedStreamHeader:
Expand All @@ -86,8 +93,9 @@ public void FuzzTarget(ReadOnlySpan<byte> bytes)
catch (NotSupportedException) { /* Reading from the stream encountered unsupported records */ }
catch (DecoderFallbackException) { /* Reading from the stream encountered an invalid UTF8 sequence. */ }
catch (EndOfStreamException) { /* The end of the stream was reached before reading SerializationRecordType.MessageEnd record. */ }
catch (IOException) { /* An I/O error occurred. */ }
}
else
else
{
try
{
Expand All @@ -97,10 +105,6 @@ public void FuzzTarget(ReadOnlySpan<byte> bytes)
catch (SerializationException) { /* Everything has to start with a header */ }
catch (NotSupportedException) { /* Reading from the stream encountered unsupported records */ }
catch (EndOfStreamException) { /* The end of the stream was reached before reading SerializationRecordType.MessageEnd record. */ }
catch (DecoderFallbackException) { /* Reading from the stream encountered an invalid UTF8 sequence. */ }
// below exceptions are not expected
catch (FormatException) { /* Temporarily catch this until its fixed */ }
catch (IOException) { /* Temporarily catch this until its fixed */ }
}
}
}
Expand Down

0 comments on commit 98b0728

Please sign in to comment.