Skip to content

Commit 31853a3

Browse files
committed
Fixing Assert at InitBoxedInlineSegments
The assert will be fired as the size of the segment can be larger than length. Say when you add a item on an Array on that size position. However the assert needs to go away along with that we need to fix the size of new Array with max of INLINE_CHUNK_SIZE, so that IsInlineSegment logic works correctly as the new Array's segment was indeed inlined. Truncating the size would not be a problem as this cannot be smaller than length and later if the size needed to be increased the current segment will be re-allocated.
1 parent 8723255 commit 31853a3

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/Runtime/Library/JavascriptArray.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11919,13 +11919,12 @@ using namespace Js;
1191911919

1192011920
if (IsInlineSegment(src, instance))
1192111921
{
11922-
Assert(src->size <= SparseArraySegmentBase::INLINE_CHUNK_SIZE);
11923-
1192411922
// Copy head segment data between inlined head segments
1192511923
dst = DetermineInlineHeadSegmentPointer<T, 0, true>(static_cast<T*>(this));
1192611924
dst->left = src->left;
1192711925
dst->length = src->length;
11928-
dst->size = src->size;
11926+
uint inlineChunkSize = SparseArraySegmentBase::INLINE_CHUNK_SIZE;
11927+
dst->size = min(src->size, inlineChunkSize);
1192911928
}
1193011929
else
1193111930
{
@@ -11940,7 +11939,8 @@ using namespace Js;
1194011939

1194111940
Assert(IsInlineSegment(src, instance) == IsInlineSegment(dst, static_cast<T*>(this)));
1194211941

11943-
CopyArray(dst->elements, dst->size, src->elements, src->size);
11942+
AssertOrFailFast(dst->size <= src->size);
11943+
CopyArray(dst->elements, dst->size, src->elements, dst->size);
1194411944

1194511945
if (!deepCopy)
1194611946
{

test/Bugs/misc_bugs.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ var tests = [
246246
test0();
247247
}
248248
},
249+
{
250+
name: "Init box javascript array : OS : 20517662",
251+
body: function () {
252+
var obj = {};
253+
obj[0] = 11;
254+
obj[1] = {};
255+
obj[17] = 222;
256+
obj[35] = 333; // This is will increase the size past the inline segment
257+
258+
Object.assign({}, obj); // The InitBoxedInlineSegments will be called due to this call.
259+
}
260+
},
249261
{
250262
name: "calling promise's function as constructor should not be allowed",
251263
body: function () {

0 commit comments

Comments
 (0)