diff --git a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/ArrayRecord.cs b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/ArrayRecord.cs index c18208668225f8..16fccd99cc1c5f 100644 --- a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/ArrayRecord.cs +++ b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/ArrayRecord.cs @@ -64,6 +64,11 @@ internal bool IsJagged /// /// An array filled with the data provided in the serialized records. /// does not match the data from the payload. + /// + /// Check the total length of the array by using property before calling this method, + /// as an attacker could have sent you a small payload that will require to allocate a very large array + /// and potentially cause and Denial of Service. + /// [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public Array GetArray(Type expectedArrayType, bool allowNulls = true) { diff --git a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/NrbfDecoder.cs b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/NrbfDecoder.cs index 76089c07ee0ce0..192fe80c6f5681 100644 --- a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/NrbfDecoder.cs +++ b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/NrbfDecoder.cs @@ -16,6 +16,10 @@ namespace System.Formats.Nrbf; /// /// Provides stateless methods for decoding .NET Remoting Binary Format (NRBF) encoded data. /// +/// +/// NrbfDecoder is an implementation of an NRBF reader, but its behaviors don't strictly follow BinaryFormatter's implementation. +/// Thus the output of NrbfDecoder shouldn't be used to determine whether a call to BinaryFormatter would be safe. +/// public static class NrbfDecoder { private static UTF8Encoding ThrowOnInvalidUtf8Encoding { get; } = new(false, throwOnInvalidBytes: true); diff --git a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SZArrayRecord.cs b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SZArrayRecord.cs index 0eef853a1e18a8..74359693604651 100644 --- a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SZArrayRecord.cs +++ b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SZArrayRecord.cs @@ -34,6 +34,11 @@ private protected SZArrayRecord(ArrayInfo arrayInfo) : base(arrayInfo) /// otherwise, . /// /// An array filled with the data provided in the serialized records. + /// + /// Check the total length of the array by using property before calling this method, + /// as an attacker could have sent you a small payload that will require to allocate a very large array + /// and potentially cause and Denial of Service. + /// public abstract T?[] GetArray(bool allowNulls = true); #pragma warning disable IL3051 // RequiresDynamicCode is not required in this particualar case diff --git a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SerializationRecord.cs b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SerializationRecord.cs index 43c51d2f864310..fa7d2eda86ca60 100644 --- a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SerializationRecord.cs +++ b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SerializationRecord.cs @@ -39,6 +39,10 @@ internal SerializationRecord() // others can't derive from this type /// Gets the name of the serialized type. /// /// The name of the serialized type. + /// + /// Since the provided type name may originate from untrusted input, + /// it should not be utilized for type loading, as it could potentially load a malicious type. + /// public abstract TypeName TypeName { get; } /// diff --git a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SerializationRecordId.cs b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SerializationRecordId.cs index a8318cb72d11de..fac6966f6abd49 100644 --- a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SerializationRecordId.cs +++ b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SerializationRecordId.cs @@ -16,6 +16,9 @@ namespace System.Formats.Nrbf; /// /// The ID of . /// +/// +/// It can be used the detect cycles in decoded records. +/// [DebuggerDisplay("{_id}")] public readonly struct SerializationRecordId : IEquatable {