Skip to content

Unsafe instantiation of arrays #4

@GrabYourPitchforks

Description

@GrabYourPitchforks

There are a few places in the code where an untrusted count / length / etc. value is used as a length argument for array creation. This allows trivial DoS via an untrusted payload specifying very large lengths but never providing any data after the length value.

private static T[] ReadPrimitiveTypes<T>(BinaryReader reader, int count)
where T : unmanaged
{
// Special casing byte for performance.
if (typeof(T) == typeof(byte))
{
byte[] bytes = reader.ReadBytes(count);
return (T[])(object)bytes;
}
T[] values = new T[count];

int memberCount = reader.ReadInt32();
string[] memberNames = new string[memberCount];

internal static MemberTypeInfo Parse(BinaryReader reader, int count)
{
(BinaryType BinaryType, object? AdditionalInfo)[] info = new (BinaryType BinaryType, object? AdditionalInfo)[count];

int length = reader.ReadInt32();
if (arrayType != BinaryArrayType.Single || rank != 1)
{
throw new NotSupportedException("Only single dimensional arrays are currently supported.");
}
MemberTypeInfo memberTypeInfo = MemberTypeInfo.Parse(reader, 1);
ClassRecord?[] records = new ClassRecord?[length];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions