Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NRBF] Fix bugs discovered by the fuzzer #107368

Merged
merged 8 commits into from
Sep 6, 2024
Merged

Conversation

adamsitnik
Copy link
Member

@adamsitnik adamsitnik commented Sep 4, 2024

  1. don't allow for values out of the SerializationRecordType enum range (I've checked the parsing of all other enums and they are already very defensive, it seems to be the only enum where we were not defensive enough)
  2. throw SerializationException rather than KeyNotFoundException when the referenced record is missing or it points to a record of different type (SerializationException is what we promise in the docs)
  3. throw SerializationException rather than FormatException when it's being thrown by BinaryReader (or sth else that we use)
  4. document the fact that IOException can be thrown
  5. throw SerializationException rather than OverflowException when parsing the decimal fails

… when the referenced record is missing or it points to a record of different type
… it's being thrown by BinaryReader (or sth else that we use)
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Sep 4, 2024
@adamsitnik adamsitnik added binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it area-System.Formats.Nrbf and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Sep 4, 2024
Copy link
Contributor

Tagging subscribers to 'binaryformatter-migration': @adamsitnik, @bartonjs, @jeffhandley, @terrajobst

{
return Decode(reader, options ?? new(), out recordMap);
}
catch (FormatException) // can be thrown by various BinaryReader methods
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass to inner exception?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't do that on purpose, to avoid leaking any information from the inner exception that could be attacker controlled (like some weird string that could somehow affect the log file).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@buyaa-n
Copy link
Contributor

buyaa-n commented Sep 5, 2024

@MihuBot fuzz NrbfDecoder -combineWith #107385

@buyaa-n
Copy link
Contributor

buyaa-n commented Sep 5, 2024

@adamsitnik somehow cannot run the fuzzer locally with this fix, had cherry-picked all commits still see the FormattingException, KeyNotFoundException, removing TempNugetCache and/or doing clean build doesn't help so running the fuzzer from your PR

@buyaa-n
Copy link
Contributor

buyaa-n commented Sep 5, 2024

Anyway there is one thing that is not fixed, getting InvalidCastExeption when there is no valid header, on:

var header = (SerializedStreamHeaderRecord)DecodeNext(reader, recordMap, AllowedRecordTypes.SerializedStreamHeader, options, out _);

I think decoder should throw when there is no header

@MihaZupan
Copy link
Member

ah, the bot was expecting the PRs to just be numbers, not full links. Should be fixed now
@MihuBot fuzz NrbfDecoder -combineWith #107385

@MihuBot
Copy link

MihuBot commented Sep 5, 2024

// NrbfDecoderFuzzer
System.InvalidCastException: Unable to cast object of type 'System.Formats.Nrbf.SystemClassWithMembersAndTypesRecord' to type 'System.Formats.Nrbf.SerializedStreamHeaderRecord'.
   at System.Formats.Nrbf.NrbfDecoder.Decode(BinaryReader reader, PayloadOptions options, IReadOnlyDictionary`2& readOnlyRecordMap)
   at System.Formats.Nrbf.NrbfDecoder.Decode(Stream payload, IReadOnlyDictionary`2& recordMap, PayloadOptions options, Boolean leaveOpen)
   at System.Formats.Nrbf.NrbfDecoder.Decode(Stream payload, PayloadOptions options, Boolean leaveOpen)
   at DotnetFuzzing.Fuzzers.NrbfDecoderFuzzer.FuzzTarget(ReadOnlySpan`1 bytes) in D:\a\runtime-utils\runtime-utils\Runner\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\NrbfDecoderFuzzer.cs:line 94
   at DotnetFuzzing.Program.<>c__DisplayClass1_0.<RunFuzzer>b__0(ReadOnlySpan`1 bytes) in D:\a\runtime-utils\runtime-utils\Runner\runtime\src\libraries\Fuzzing\DotnetFuzzing\Program.cs:line 91
   at SharpFuzz.Fuzzer.LibFuzzer.Run(ReadOnlySpanAction action, Boolean ignoreExceptions)
==6968== ERROR: libFuzzer: deadly signal
NOTE: libFuzzer has rudimentary signal handlers.
      Combine libFuzzer with AddressSanitizer or similar for better crash reports.
SUMMARY: libFuzzer: deadly signal
MS: 3 ChangeBinInt-CopyPart-PersAutoDict- DE: "\377\377\377\377"-; base unit: 2c8961024dcdbe30195b1c293ff3526580f4bf98
0x60,0xff,0xff,0xff,0x0,0x2,0x0,0x79,0xff,0xff,0xff,0xff,0xff,0xff,
`\377\377\377\000\002\000y\377\377\377\377\377\377
artifact_prefix='./'; Test unit written to NrbfDecoderFuzzer-artifact-3
Base64: YP///wACAHn///////8=

@adamsitnik
Copy link
Member Author

somehow cannot run the fuzzer locally with this fix

In your PR, you are referencing the NuGet package, not the local project:

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

had cherry-picked all commits still see the FormattingException, KeyNotFoundException, removing TempNugetCache and/or doing clean build doesn't help so running the fuzzer from your PR

What I did to get this working (it's ugly, there must be a better way):

  1. I had referenced the .dll file from the output
  <ItemGroup>
    <Reference Include="System.Formats.Nrbf">
      <HintPath>..\..\..\..\artifacts\bin\System.Formats.Nrbf\Debug\net8.0\System.Formats.Nrbf.dll</HintPath>
    </Reference>
  </ItemGroup>
  1. Full build of the solution:
.\dotnet.cmd build .\src\libraries\System.Formats.Nrbf\System.Formats.Nrbf.sln
  1. Removal of:
Fuzzing\TempNugetCache
DotnetFuzzing\bin
DotnetFuzzing\obj
DotnetFuzzing\deployment
DotnetFuzzing\publish
  1. Clean publish:
D:\projects\runtime\dotnet.cmd publish -o publish; publish/DotnetFuzzing.exe prepare-onefuzz deployment
.\deployment\NrbfDecoderFuzzer\local-run.bat

@adamsitnik
Copy link
Member Author

I think decoder should throw when there is no header

It will (I have added the fix for that with a test in my first commit), the AllowedRecordTypes.SerializedStreamHeader passed to DecodeNext is now going to be respected.

More info: the (((uint)allowed & (1u << nextByte)) == 0) check was working fine, but there was no check for values out of range:

byte nextByte = reader.ReadByte();
if (((uint)allowed & (1u << nextByte)) == 0)

The fuzzer was smart enough to generate a value that made it pass (64 IIRC), I have simply added a check that rejects values out of the enum range:

if (nextByte > (byte)SerializationRecordType.MethodReturn // MethodReturn is the last defined value.
|| (nextByte > (byte)SerializationRecordType.ArraySingleString && nextByte < (byte)SerializationRecordType.MethodCall) // not part of the spec
|| ((uint)allowed & (1u << nextByte)) == 0) // valid, but not allowed

@buyaa-n
Copy link
Contributor

buyaa-n commented Sep 5, 2024

What I did to get this working (it's ugly, there must be a better way):

Local testing unblocked with this, thanks!

@buyaa-n
Copy link
Contributor

buyaa-n commented Sep 5, 2024

@MihuBot fuzz NrbfDecoder -combineWith #107385

Copy link
Contributor

@buyaa-n buyaa-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes LGTM and the fuzzer runs more stable with the fix, thanks!

@MihuBot
Copy link

MihuBot commented Sep 5, 2024

// NrbfDecoderFuzzer
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'primitiveType')
Actual value was None.
   at System.Formats.Nrbf.Utils.TypeNameHelpers.GetPrimitiveTypeName(PrimitiveType primitiveType)
   at System.Formats.Nrbf.Utils.TypeNameHelpers.GetPrimitiveSZArrayTypeName(PrimitiveType primitiveType)
   at System.Formats.Nrbf.MemberTypeInfo.GetArrayTypeName(ArrayInfo arrayInfo)
   at System.Formats.Nrbf.RectangularArrayRecord.get_TypeName()
   at DotnetFuzzing.Fuzzers.NrbfDecoderFuzzer.Test(Span`1 testSpan, MemoryStream stream) in D:\a\runtime-utils\runtime-utils\Runner\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\NrbfDecoderFuzzer.cs:line 54
   at DotnetFuzzing.Fuzzers.NrbfDecoderFuzzer.FuzzTarget(ReadOnlySpan`1 bytes) in D:\a\runtime-utils\runtime-utils\Runner\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\NrbfDecoderFuzzer.cs:line 26
   at SharpFuzz.Fuzzer.LibFuzzer.Run(ReadOnlySpanAction action, Boolean ignoreExceptions)
==5528== ERROR: libFuzzer: deadly signal
NOTE: libFuzzer has rudimentary signal handlers.
      Combine libFuzzer with AddressSanitizer or similar for better crash reports.
SUMMARY: libFuzzer: deadly signal
MS: 2 PersAutoDict-CrossOver- DE: "\027\000\000\000\000\000\000\000"-; base unit: ffebe89a47996df7bdece2ff81cd402ef01878aa
0x0,0x1,0x0,0x0,0x0,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x1,0x0,0x0,0x0,0x2,0x8,0x0,0x0,0x0,0x0,0x0,0x17,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x1,0x17,0xf4,0x0,0x2,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x0,0xb,0x0,0x0,0x4,
\000\001\000\000\000\377\377\377\377\001\000\000\000\000\000\000\000\007\001\000\000\000\002\010\000\000\000\000\000\027\000\000\000\000\000\000\000\000\000\000\007\001\027\364\000\002\010\000\000\000\000\000\000\000\000\000\000\000\000\007\000\013\000\000\004
artifact_prefix='./'; Test unit written to NrbfDecoderFuzzer-artifact-3
Base64: AAEAAAD/////AQAAAAAAAAAHAQAAAAIIAAAAAAAXAAAAAAAAAAAAAAcBF/QAAggAAAAAAAAAAAAAAAAHAAsAAAQ=

@adamsitnik
Copy link
Member Author

@MihuBot fuzz NrbfDecoder -combineWith #107385

@MihuBot
Copy link

MihuBot commented Sep 6, 2024

// NrbfDecoderFuzzer
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'primitiveType')
Actual value was Null.
   at System.Formats.Nrbf.Utils.TypeNameHelpers.GetPrimitiveTypeName(PrimitiveType primitiveType)
   at System.Formats.Nrbf.Utils.TypeNameHelpers.GetPrimitiveSZArrayTypeName(PrimitiveType primitiveType)
   at System.Formats.Nrbf.MemberTypeInfo.GetArrayTypeName(ArrayInfo arrayInfo)
   at System.Formats.Nrbf.RectangularArrayRecord.get_TypeName()
   at DotnetFuzzing.Fuzzers.NrbfDecoderFuzzer.Test(Span`1 testSpan, MemoryStream stream) in D:\runner-dir\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\NrbfDecoderFuzzer.cs:line 54
   at DotnetFuzzing.Fuzzers.NrbfDecoderFuzzer.FuzzTarget(ReadOnlySpan`1 bytes) in D:\runner-dir\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\NrbfDecoderFuzzer.cs:line 26
   at SharpFuzz.Fuzzer.LibFuzzer.Run(ReadOnlySpanAction action, Boolean ignoreExceptions)
==6440== ERROR: libFuzzer: deadly signal
NOTE: libFuzzer has rudimentary signal handlers.
      Combine libFuzzer with AddressSanitizer or similar for better crash reports.
SUMMARY: libFuzzer: deadly signal
MS: 1 CrossOver-; base unit: 7967cc6c6d0c11820eef8f9d8bd26cb641d25cd9
0x0,0x1,0x0,0x0,0x0,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x1,0x0,0x0,0x0,0x2,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x10,0x0,0x0,0x0,0x0,0x0,0x7,0x1,0x17,0xf4,0x0,0x2,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x10,0x0,0x0,0x7,0x11,0xb,
\000\001\000\000\000\377\377\377\377\001\000\000\000\000\000\000\000\007\001\000\000\000\002\010\000\000\000\000\000\000\000\000\001\000\020\000\000\000\000\000\007\001\027\364\000\002\010\000\000\000\000\000\000\000\001\000\020\000\000\007\021\013
artifact_prefix='./'; Test unit written to NrbfDecoderFuzzer-artifact-3
Base64: AAEAAAD/////AQAAAAAAAAAHAQAAAAIIAAAAAAAAAAABABAAAAAAAAcBF/QAAggAAAAAAAAAAQAQAAAHEQs=

@adamsitnik
Copy link
Member Author

@MihuBot fuzz NrbfDecoder -combineWith #107385

@MihuBot
Copy link

MihuBot commented Sep 6, 2024

// NrbfDecoderFuzzer
System.ArgumentException: The output char buffer is too small to contain the decoded characters, encoding codepage '65001' and fallback 'System.Text.DecoderExceptionFallback'. (Parameter 'chars')
   at System.Text.Encoding.ThrowCharsOverflow(DecoderNLS decoder, Boolean nothingDecoded)
   at System.Text.DecoderNLS.DrainLeftoverDataForGetChars(ReadOnlySpan`1 bytes, Span`1 chars, Int32& bytesConsumed)
   at System.Text.Encoding.GetCharsWithFallback(Byte* pOriginalBytes, Int32 originalByteCount, Char* pOriginalChars, Int32 originalCharCount, Int32 bytesConsumedSoFar, Int32 charsWrittenSoFar, DecoderNLS decoder)
   at System.Text.Encoding.GetChars(Byte* pBytes, Int32 byteCount, Char* pChars, Int32 charCount, DecoderNLS decoder)
   at System.IO.BinaryReader.Read()
   at System.IO.BinaryReader.ReadChar()
   at System.Formats.Nrbf.Utils.BinaryReaderExtensions.ReadPrimitiveValue(BinaryReader reader, PrimitiveType primitiveType)
   at System.Formats.Nrbf.NrbfDecoder.Decode(BinaryReader reader, PayloadOptions options, IReadOnlyDictionary`2& readOnlyRecordMap)
   at System.Formats.Nrbf.NrbfDecoder.Decode(Stream payload, IReadOnlyDictionary`2& recordMap, PayloadOptions options, Boolean leaveOpen)
   at DotnetFuzzing.Fuzzers.NrbfDecoderFuzzer.Test(Span`1 testSpan, MemoryStream stream) in D:\runner-dir\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\NrbfDecoderFuzzer.cs:line 36
   at DotnetFuzzing.Fuzzers.NrbfDecoderFuzzer.FuzzTarget(ReadOnlySpan`1 bytes) in D:\runner-dir\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\NrbfDecoderFuzzer.cs:line 26
   at SharpFuzz.Fuzzer.LibFuzzer.Run(ReadOnlySpanAction action, Boolean ignoreExceptions)
==5504== ERROR: libFuzzer: deadly signal
NOTE: libFuzzer has rudimentary signal handlers.
      Combine libFuzzer with AddressSanitizer or similar for better crash reports.
SUMMARY: libFuzzer: deadly signal
MS: 2 InsertByte-InsertRepeatedBytes-; base unit: b2b49562056a89e3cc3139d38dd5fc79054b1d01
0x0,0x1,0x0,0x0,0x41,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x1,0x17,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0xa,0x1,0x0,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0xf3,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0x3,0x10,0x0,0x0,0x0,0x0,0x0,
\000\001\000\000A\377\377\377\377\001\000\000\000\000\000\000\000\007\001\027\000\000\000\001\000\000\000\000\000\012\001\000\003\003\003\003\003\003\003\003\003\003\363\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\277\003\020\000\000\000\000\000
artifact_prefix='./'; Test unit written to NrbfDecoderFuzzer-artifact-2
Base64: AAEAAEH/////AQAAAAAAAAAHARcAAAABAAAAAAAKAQADAwMDAwMDAwMD87+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/vwMQAAAAAAA=

@adamsitnik
Copy link
Member Author

@MihuBot fuzz NrbfDecoder

@buyaa-n
Copy link
Contributor

buyaa-n commented Sep 6, 2024

/ba-g the one unknown CI failure is unrelated and the failure log has no any info for filing an issue

@buyaa-n buyaa-n merged commit e79426e into dotnet:main Sep 6, 2024
81 of 85 checks passed
adamsitnik added a commit to adamsitnik/runtime that referenced this pull request Sep 13, 2024
* bug #1: don't allow for values out of the SerializationRecordType enum range

* bug #2: throw SerializationException rather than KeyNotFoundException when the referenced record is missing or it points to a record of different type

* bug #3: throw SerializationException rather than FormatException when it's being thrown by BinaryReader (or sth else that we use)

* bug #4: document the fact that IOException can be thrown

* bug #5: throw SerializationException rather than OverflowException when parsing the decimal fails

* bug #6: 0 and 17 are illegal values for PrimitiveType enum

* bug #7: throw SerializationException when a surrogate character is read (so far an ArgumentException was thrown)
# Conflicts:
#	src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/NrbfDecoder.cs
jtschuster pushed a commit to jtschuster/runtime that referenced this pull request Sep 17, 2024
* bug #1: don't allow for values out of the SerializationRecordType enum range

* bug dotnet#2: throw SerializationException rather than KeyNotFoundException when the referenced record is missing or it points to a record of different type

* bug dotnet#3: throw SerializationException rather than FormatException when it's being thrown by BinaryReader (or sth else that we use)

* bug dotnet#4: document the fact that IOException can be thrown

* bug dotnet#5: throw SerializationException rather than OverflowException when parsing the decimal fails

* bug dotnet#6: 0 and 17 are illegal values for PrimitiveType enum

* bug dotnet#7: throw SerializationException when a surrogate character is read (so far an ArgumentException was thrown)
carlossanlop pushed a commit that referenced this pull request Sep 17, 2024
* [NRBF] Don't use Unsafe.As when decoding DateTime(s) (#105749)

* Add NrbfDecoder Fuzzer (#107385)

* [NRBF] Fix bugs discovered by the fuzzer (#107368)

* bug #1: don't allow for values out of the SerializationRecordType enum range

* bug #2: throw SerializationException rather than KeyNotFoundException when the referenced record is missing or it points to a record of different type

* bug #3: throw SerializationException rather than FormatException when it's being thrown by BinaryReader (or sth else that we use)

* bug #4: document the fact that IOException can be thrown

* bug #5: throw SerializationException rather than OverflowException when parsing the decimal fails

* bug #6: 0 and 17 are illegal values for PrimitiveType enum

* bug #7: throw SerializationException when a surrogate character is read (so far an ArgumentException was thrown)
# Conflicts:
#	src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/NrbfDecoder.cs

* [NRBF] throw SerializationException when a surrogate character is read (#107532)

 (so far an ArgumentException was thrown)

* [NRBF] Fuzzing non-seekable stream input (#107605)

* [NRBF] More bug fixes (#107682)

- Don't use `Debug.Fail` not followed by an exception (it may cause problems for apps deployed in Debug)
- avoid Int32 overflow
- throw for unexpected enum values just in case parsing has not rejected them
- validate the number of chars read by BinaryReader.ReadChars
- pass serialization record id to ex message
- return false rather than throw EndOfStreamException when provided Stream has not enough data
- don't restore the position in finally 
- limit max SZ and MD array length to Array.MaxLength, stop using LinkedList<T> as List<T> will be able to hold all elements now
- remove internal enum values that were always illegal, but needed to be handled everywhere
- Fix DebuggerDisplay

* [NRBF] Comments and bug fixes from internal code review (#107735)

* copy comments and asserts from Levis internal code review

* apply Levis suggestion: don't store Array.MaxLength as a const, as it may change in the future

* add missing and fix some of the existing comments

* first bug fix: SerializationRecord.TypeNameMatches should throw ArgumentNullException for null Type argument

* second bug fix: SerializationRecord.TypeNameMatches should know the difference between SZArray and single-dimension, non-zero offset arrays (example: int[] and int[*])

* third bug fix: don't cast bytes to booleans

* fourth bug fix: don't cast bytes to DateTimes

* add one test case that I've forgot in previous PR
# Conflicts:
#	src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SerializationRecord.cs

* [NRBF] Address issues discovered by Threat Model  (#106629)

* introduce ArrayRecord.FlattenedLength

* do not include invalid Type or Assembly names in the exception messages, as it's most likely corrupted/tampered/malicious data and could be used as a vector of attack.

* It is possible to have binary array records have an element type of array without being marked as jagged

---------

Co-authored-by: Buyaa Namnan <bunamnan@microsoft.com>
sirntar pushed a commit to sirntar/runtime that referenced this pull request Sep 30, 2024
* bug #1: don't allow for values out of the SerializationRecordType enum range

* bug #2: throw SerializationException rather than KeyNotFoundException when the referenced record is missing or it points to a record of different type

* bug #3: throw SerializationException rather than FormatException when it's being thrown by BinaryReader (or sth else that we use)

* bug dotnet#4: document the fact that IOException can be thrown

* bug dotnet#5: throw SerializationException rather than OverflowException when parsing the decimal fails

* bug dotnet#6: 0 and 17 are illegal values for PrimitiveType enum

* bug dotnet#7: throw SerializationException when a surrogate character is read (so far an ArgumentException was thrown)
@github-actions github-actions bot locked and limited conversation to collaborators Oct 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Formats.Nrbf binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants