Skip to content

Commit d7bad19

Browse files
authored
Add asserts and sanity checks on HB Array handling (#3051)
***NO_CI***
1 parent 770af05 commit d7bad19

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/CLR/Core/CLR_RT_HeapBlock_Array.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,20 @@ HRESULT CLR_RT_HeapBlock_Array::Copy(
322322
dataSrc += indexSrc * sizeElem;
323323
dataDst += indexDst * sizeElem;
324324

325+
#if !defined(BUILD_RTM)
326+
// Validate pointers and memory ranges
327+
if (dataSrc == nullptr || dataDst == nullptr ||
328+
dataSrc + length * sizeElem > arraySrc->GetFirstElement() + arraySrc->m_numOfElements * sizeElem ||
329+
dataDst + length * sizeElem > arrayDst->GetFirstElement() + arrayDst->m_numOfElements * sizeElem)
330+
{
331+
#ifdef DEBUG
332+
_ASSERTE(FALSE);
333+
#endif
334+
335+
NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE);
336+
}
337+
#endif
338+
325339
if (!arraySrc->m_fReference)
326340
{
327341
memmove(dataDst, dataSrc, length * sizeElem);

0 commit comments

Comments
 (0)