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

Unsafe instantiation of arrays #4

Closed
GrabYourPitchforks opened this issue Mar 4, 2024 · 1 comment
Closed

Unsafe instantiation of arrays #4

GrabYourPitchforks opened this issue Mar 4, 2024 · 1 comment

Comments

@GrabYourPitchforks
Copy link

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];

@adamsitnik
Copy link
Owner

adamsitnik commented Mar 5, 2024

What would be the proper fix? Allocate Lists with default capacity and just add items?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants