Skip to content

Commit b786ecf

Browse files
Chakra Automationpleath
authored andcommitted
Fail on unexpected missing item constant in an array head segment during native array conversion
1 parent 3d6226c commit b786ecf

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/Runtime/Library/JavascriptArray.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
// TODO: Change this generic fatal error to the descriptive one.
1111
#define AssertAndFailFast(x) if (!(x)) { Assert(x); Js::Throw::FatalInternalError(); }
12+
#define AssertMsgAndFailFast(x, m) if (!(x)) { AssertMsg((x), m); Js::Throw::FatalInternalError(); }
1213

1314
using namespace Js;
1415

@@ -1758,6 +1759,7 @@ using namespace Js;
17581759
ival = ((SparseArraySegment<int32>*)seg)->elements[i /*+ seg->length*/];
17591760
if (ival == JavascriptNativeIntArray::MissingItem)
17601761
{
1762+
AssertMsgAndFailFast(newSeg != intArray->head || !intArray->HasNoMissingValues(), "Unexpected missing item during array conversion");
17611763
continue;
17621764
}
17631765
newSeg->elements[i] = (double)ival;
@@ -2025,6 +2027,7 @@ using namespace Js;
20252027
ival = ((SparseArraySegment<int32>*)seg)->elements[i];
20262028
if (ival == JavascriptNativeIntArray::MissingItem)
20272029
{
2030+
AssertMsgAndFailFast(seg != intArray->head || !intArray->HasNoMissingValues(), "Unexpected missing item during array conversion");
20282031
continue;
20292032
}
20302033
newSeg->elements[i] = JavascriptNumber::ToVar(ival, scriptContext);
@@ -2059,6 +2062,7 @@ using namespace Js;
20592062
ival = ((SparseArraySegment<int32>*)seg)->elements[i];
20602063
if (ival == JavascriptNativeIntArray::MissingItem)
20612064
{
2065+
AssertMsgAndFailFast(seg != intArray->head || !intArray->HasNoMissingValues(), "Unexpected missing item during array conversion");
20622066
((SparseArraySegment<Var>*)seg)->elements[i] = (Var)JavascriptArray::MissingItem;
20632067
}
20642068
else
@@ -2238,6 +2242,7 @@ using namespace Js;
22382242
{
22392243
if (SparseArraySegment<double>::IsMissingItem(&((SparseArraySegment<double>*)seg)->elements[i]))
22402244
{
2245+
AssertMsgAndFailFast(seg != fArray->head || !fArray->HasNoMissingValues(), "Unexpected missing item during conversion");
22412246
if (seg == newSeg)
22422247
{
22432248
newSeg->elements[i] = (Var)JavascriptArray::MissingItem;

lib/Runtime/Library/SparseArraySegment.inl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,12 @@ namespace Js
268268
Assert(sizeof(T) % sizeof(Var) == 0);
269269
uint step = sizeof(T) / sizeof(Var);
270270

271-
for (uint i = start; i < size * step; i++)
271+
// We're filling [length...size-1] based on the element size. If this is going to be a float segment on 32-bit,
272+
// only fill past the point where the float elements will reside. Size * step has to be a 32-bit number.
273+
start *= step;
274+
size *= step;
275+
276+
for (uint i = start; i < size; i++)
272277
{
273278
((Var*)(this->elements))[i] = fill; // swb: no write barrier, set to non-GC pointer
274279
}

0 commit comments

Comments
 (0)