File tree Expand file tree Collapse file tree 5 files changed +21
-0
lines changed
src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf Expand file tree Collapse file tree 5 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,11 @@ internal bool IsJagged
6464 /// </param>
6565 /// <returns>An array filled with the data provided in the serialized records.</returns>
6666 /// <exception cref="InvalidOperationException"><paramref name="expectedArrayType" /> does not match the data from the payload.</exception>
67+ /// <remarks>
68+ /// Check the total length of the array by using <see cref="Lengths"/> property before calling this method,
69+ /// as an attacker could have sent you a small payload that will require to allocate a very large array
70+ /// and potentially cause <see cref="OutOfMemoryException"/> and Denial of Service.
71+ /// </remarks>
6772 [ RequiresDynamicCode ( "The code for an array of the specified type might not be available." ) ]
6873 public Array GetArray ( Type expectedArrayType , bool allowNulls = true )
6974 {
Original file line number Diff line number Diff line change @@ -16,6 +16,10 @@ namespace System.Formats.Nrbf;
1616/// <summary>
1717/// Provides stateless methods for decoding .NET Remoting Binary Format (NRBF) encoded data.
1818/// </summary>
19+ /// <remarks>
20+ /// NrbfDecoder is an implementation of an NRBF reader, but its behaviors don't strictly follow BinaryFormatter's implementation.
21+ /// Thus the output of NrbfDecoder shouldn't be used to determine whether a call to BinaryFormatter would be safe.
22+ /// </remarks>
1923public static class NrbfDecoder
2024{
2125 private static UTF8Encoding ThrowOnInvalidUtf8Encoding { get ; } = new ( false , throwOnInvalidBytes : true ) ;
Original file line number Diff line number Diff line change @@ -34,6 +34,11 @@ private protected SZArrayRecord(ArrayInfo arrayInfo) : base(arrayInfo)
3434 /// otherwise, <see langword="false" />.
3535 /// </param>
3636 /// <returns>An array filled with the data provided in the serialized records.</returns>
37+ /// <remarks>
38+ /// Check the total length of the array by using <see cref="Length"/> property before calling this method,
39+ /// as an attacker could have sent you a small payload that will require to allocate a very large array
40+ /// and potentially cause <see cref="OutOfMemoryException"/> and Denial of Service.
41+ /// </remarks>
3742 public abstract T ? [ ] GetArray ( bool allowNulls = true ) ;
3843
3944#pragma warning disable IL3051 // RequiresDynamicCode is not required in this particualar case
Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ internal SerializationRecord() // others can't derive from this type
3939 /// Gets the name of the serialized type.
4040 /// </summary>
4141 /// <value>The name of the serialized type.</value>
42+ /// <remarks>
43+ /// Since the provided type name may originate from untrusted input,
44+ /// it should not be utilized for type loading, as it could potentially load a malicious type.
45+ /// </remarks>
4246 public abstract TypeName TypeName { get ; }
4347
4448 /// <summary>
Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ namespace System.Formats.Nrbf;
1616/// <summary>
1717/// The ID of <see cref="SerializationRecord" />.
1818/// </summary>
19+ /// <remarks>
20+ /// It can be used the detect cycles in decoded records.
21+ /// </remarks>
1922[ DebuggerDisplay ( "{_id}" ) ]
2023public readonly struct SerializationRecordId : IEquatable < SerializationRecordId >
2124{
You can’t perform that action at this time.
0 commit comments