Skip to content

Commit 28928cb

Browse files
akroshgMSLaguana
authored andcommitted
[CVE-2018-1022] Inline segment is passed to another array - Internal
1 parent 1b56f9f commit 28928cb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/Runtime/Library/JavascriptArray.inl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ namespace Js
155155
DetermineInlineHeadSegmentPointer<T, InlinePropertySlots, false>(array);
156156
if(wasZeroAllocated)
157157
{
158+
AssertOrFailFast(size <= SparseArraySegmentBase::INLINE_CHUNK_SIZE);
158159
if(length != 0)
159160
{
160161
head->length = length;
@@ -238,6 +239,14 @@ namespace Js
238239
DetermineAllocationSize<className, inlineSlots>(length, &allocationPlusSize, &alignedInlineElementSlots);
239240
}
240241

242+
// alignedInlineElementSlots is actually the 'size' of the segment. The size of the segment should not be greater than InlineHead segment limit, otherwise the inline
243+
// segment may not be interpreted as inline segment if the length extends to the size.
244+
// the size could increase because of allignment.
245+
// Update the size so that it does not exceed SparseArraySegmentBase::INLINE_CHUNK_SIZE.
246+
247+
uint inlineChunkSize = SparseArraySegmentBase::INLINE_CHUNK_SIZE;
248+
uint size = min(alignedInlineElementSlots, inlineChunkSize);
249+
241250
array = RecyclerNewPlusZ(recycler, allocationPlusSize, className, length, arrayType);
242251

243252
// An new array's head segment length is initialized to zero despite the array length being nonzero because the segment
@@ -250,9 +259,9 @@ namespace Js
250259
// a variable until it is fully initialized, there is no way for script code to use the array while it still has missing
251260
// values.
252261
SparseArraySegment<unitType> *head =
253-
InitArrayAndHeadSegment<className, inlineSlots>(array, length, alignedInlineElementSlots, true);
262+
InitArrayAndHeadSegment<className, inlineSlots>(array, length, size, true);
254263

255-
head->FillSegmentBuffer(length, alignedInlineElementSlots);
264+
head->FillSegmentBuffer(length, size);
256265

257266
Assert(array->HasNoMissingValues());
258267
return array;

0 commit comments

Comments
 (0)