Skip to content

Unable to allocate very big arrays #939

@MichalStrehovsky

Description

@MichalStrehovsky

We have System.Runtime tests that test allocating the maximally supported arrays. We throw an OutOfMemoryException for them. Likely because this code:

// higher limit for array of bytes (or one byte structs) for backward compatibility.
// Keep in sync with Array.MaxArrayLength in BCL.
if (cbSize > MaxByteArrayLength /* note: comparing allocation size with element count */)
{
// Ensure the above if check covers the minimal interesting size
static_assert(MaxByteArrayLength < (uint64_t)MaxArrayLength * 2, "");
if (pEEType->IsArray())
{
if (pEEType->get_ComponentSize() != 1)
{
size_t elementCount = (cbSize - pEEType->get_BaseSize()) / pEEType->get_ComponentSize();
if (elementCount > MaxArrayLength)
return NULL;
}
else
{
size_t elementCount = cbSize - pEEType->get_BaseSize();
if (elementCount > MaxByteArrayLength)
return NULL;
}
}
}
if (cbSize >= RH_LARGE_OBJECT_SIZE)

Is checking the allocation size instead of element count. Allocation size has already been aligned up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-NativeAOT-coreclr.NET runtime optimized for ahead of time compilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions