Skip to content

Commit

Permalink
Handle possible array size overflow
Browse files Browse the repository at this point in the history
In the StackTraceArray::Allocate
  • Loading branch information
janvorli committed Jun 10, 2024
1 parent f774c60 commit d056127
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/coreclr/vm/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1484,14 +1484,14 @@ void StackTraceArray::Allocate(size_t size)
}
CONTRACTL_END;

size_t raw_size = size * sizeof(StackTraceElement) + sizeof(ArrayHeader);
S_SIZE_T raw_size = S_SIZE_T(size) * S_SIZE_T(sizeof(StackTraceElement)) + S_SIZE_T(sizeof(ArrayHeader));

if (!FitsIn<DWORD>(raw_size))
if (raw_size.IsOverflow() || !FitsIn<DWORD>(raw_size.Value())
{
EX_THROW(EEMessageException, (kOverflowException, IDS_EE_ARRAY_DIMENSIONS_EXCEEDED));
}

SetArray(I1ARRAYREF(AllocatePrimitiveArray(ELEMENT_TYPE_I1, static_cast<DWORD>(raw_size))));
SetArray(I1ARRAYREF(AllocatePrimitiveArray(ELEMENT_TYPE_I1, static_cast<DWORD>(raw_size.Value()))));
SetSize(0);
SetKeepAliveItemsCount(0);
SetObjectThread();
Expand Down

0 comments on commit d056127

Please sign in to comment.