@@ -18,10 +18,18 @@ internal sealed class NrbfDecoderFuzzer : IFuzzer
1818
1919 public void FuzzTarget ( ReadOnlySpan < byte > bytes )
2020 {
21- using PooledBoundedMemory < byte > inputPoisoned = PooledBoundedMemory < byte > . Rent ( bytes , PoisonPagePlacement . After ) ;
22- using MemoryStream stream = new MemoryStream ( inputPoisoned . Memory . ToArray ( ) ) ;
21+ using PooledBoundedMemory < byte > inputPoisonedAfter = PooledBoundedMemory < byte > . Rent ( bytes , PoisonPagePlacement . After ) ;
22+ using PooledBoundedMemory < byte > inputPoisonedBefore = PooledBoundedMemory < byte > . Rent ( bytes , PoisonPagePlacement . Before ) ;
23+ using MemoryStream streamAfter = new MemoryStream ( inputPoisonedAfter . Memory . ToArray ( ) ) ;
24+ using MemoryStream streamBefore = new MemoryStream ( inputPoisonedBefore . Memory . ToArray ( ) ) ;
2325
24- if ( NrbfDecoder . StartsWithPayloadHeader ( inputPoisoned . Span ) )
26+ Test ( inputPoisonedAfter . Span , streamAfter ) ;
27+ Test ( inputPoisonedBefore . Span , streamBefore ) ;
28+ }
29+
30+ private static void Test ( Span < byte > testSpan , MemoryStream stream )
31+ {
32+ if ( NrbfDecoder . StartsWithPayloadHeader ( testSpan ) )
2533 {
2634 try
2735 {
@@ -52,15 +60,14 @@ public void FuzzTarget(ReadOnlySpan<byte> bytes)
5260 case SerializationRecordType . ClassWithId :
5361 case SerializationRecordType . ClassWithMembersAndTypes :
5462 case SerializationRecordType . SystemClassWithMembersAndTypes :
55- {
5663 ClassRecord classRecord = ( ClassRecord ) record ;
5764 Assert . NotNull ( classRecord . TypeName ) ;
5865
5966 foreach ( string name in classRecord . MemberNames )
6067 {
6168 Assert . Equal ( true , classRecord . HasMember ( name ) ) ;
6269 }
63- } break ;
70+ break ;
6471 case SerializationRecordType . MemberPrimitiveTyped :
6572 PrimitiveTypeRecord primitiveType = ( PrimitiveTypeRecord ) record ;
6673 Assert . NotNull ( primitiveType . Value ) ;
@@ -72,7 +79,7 @@ public void FuzzTarget(ReadOnlySpan<byte> bytes)
7279 case SerializationRecordType . ObjectNull :
7380 case SerializationRecordType . ObjectNullMultiple :
7481 case SerializationRecordType . ObjectNullMultiple256 :
75- Assert . Equal ( default , record . Id ) ;
82+ // Assert.Equal(default, record.Id);
7683 break ;
7784 case SerializationRecordType . MessageEnd :
7885 case SerializationRecordType . SerializedStreamHeader :
@@ -86,8 +93,9 @@ public void FuzzTarget(ReadOnlySpan<byte> bytes)
8693 catch ( NotSupportedException ) { /* Reading from the stream encountered unsupported records */ }
8794 catch ( DecoderFallbackException ) { /* Reading from the stream encountered an invalid UTF8 sequence. */ }
8895 catch ( EndOfStreamException ) { /* The end of the stream was reached before reading SerializationRecordType.MessageEnd record. */ }
96+ catch ( IOException ) { /* An I/O error occurred. */ }
8997 }
90- else
98+ else
9199 {
92100 try
93101 {
@@ -97,10 +105,6 @@ public void FuzzTarget(ReadOnlySpan<byte> bytes)
97105 catch ( SerializationException ) { /* Everything has to start with a header */ }
98106 catch ( NotSupportedException ) { /* Reading from the stream encountered unsupported records */ }
99107 catch ( EndOfStreamException ) { /* The end of the stream was reached before reading SerializationRecordType.MessageEnd record. */ }
100- catch ( DecoderFallbackException ) { /* Reading from the stream encountered an invalid UTF8 sequence. */ }
101- // below exceptions are not expected
102- catch ( FormatException ) { /* Temporarily catch this until its fixed */ }
103- catch ( IOException ) { /* Temporarily catch this until its fixed */ }
104108 }
105109 }
106110 }
0 commit comments