Skip to content

Conversation

adamsitnik
Copy link
Member

A brief explanation of how I've implemented it:

  • The first record we read, must be an NRBF header. It provides RootId, but nothing else (its type etc).
  • From here, the payload can contain BinaryLibraryRecord at any point.
  • If the first actual record is a ClassRecord with any members or ArrayRecord with any items, a stack is being populated with information of expected record type. We read those records and if there is a type mismatch, we throw.
  • Most records may contain references, in such a case we store information about what is the expected record type (what the reference should be pointing to) and store the reference in record map.
  • We read the referenced records and if there is a type mismatch (example: an array of strings containing a reference to binary library), we throw.

@GrabYourPitchforks PTAL and let me know if you have any concerns. I would be happy to convert specific scenarios into test cases.

@adamsitnik adamsitnik added binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it area-System.Formats.Nrbf labels Jun 18, 2024
@adamsitnik adamsitnik added this to the 9.0.0 milestone Jun 18, 2024
@adamsitnik adamsitnik self-assigned this Jun 18, 2024
{
record = memberReference.GetReferencedRecord();

if (record is not BinaryObjectStringRecord)
Copy link
Member Author

Choose a reason for hiding this comment

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

this check is no longer needed here, as there is a universal check for all references in RecordMap.Add. The benefit is that we throw as soon as we encounter an invalid reference.

# Conflicts:
#	src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SerializationRecordId.cs
# Conflicts:
#	src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/NrbfDecoder.cs
#	src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/Utils/ThrowHelper.cs
@jeffhandley
Copy link
Member

We are going to discuss this further to decide if we want to change this logic in .NET 9 or document that the decoder does not reject these records. We could potentially add this logic in .NET 10 with the PayloadOptions offering a setting for whether or not they should be rejected.

This is therefore not blocking the release.

# Conflicts:
#	src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/MemberReferenceRecord.cs
#	src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/NrbfDecoder.cs
#	src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/RecordMap.cs
#	src/libraries/System.Formats.Nrbf/tests/InvalidInputTests.cs
#	src/libraries/System.Formats.Nrbf/tests/System.Formats.Nrbf.Tests.csproj
@adamsitnik adamsitnik closed this Sep 17, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 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.

2 participants