Skip to content

Commit d056127

Browse files
committed
Handle possible array size overflow
In the StackTraceArray::Allocate
1 parent f774c60 commit d056127

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/coreclr/vm/object.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1484,14 +1484,14 @@ void StackTraceArray::Allocate(size_t size)
14841484
}
14851485
CONTRACTL_END;
14861486

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

1489-
if (!FitsIn<DWORD>(raw_size))
1489+
if (raw_size.IsOverflow() || !FitsIn<DWORD>(raw_size.Value())
14901490
{
14911491
EX_THROW(EEMessageException, (kOverflowException, IDS_EE_ARRAY_DIMENSIONS_EXCEEDED));
14921492
}
14931493

1494-
SetArray(I1ARRAYREF(AllocatePrimitiveArray(ELEMENT_TYPE_I1, static_cast<DWORD>(raw_size))));
1494+
SetArray(I1ARRAYREF(AllocatePrimitiveArray(ELEMENT_TYPE_I1, static_cast<DWORD>(raw_size.Value()))));
14951495
SetSize(0);
14961496
SetKeepAliveItemsCount(0);
14971497
SetObjectThread();

0 commit comments

Comments
 (0)