Skip to content

Commit 9296ec5

Browse files
committed
[1.11>master] [MERGE #6167 @pleath] Fail on unexpected missing item constant in an array head segment during native array conversion
Merge pull request #6167 from pleath:arrayfail
2 parents 20be9e1 + ba1f445 commit 9296ec5

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

@@ -1749,6 +1750,7 @@ using namespace Js;
17491750
ival = ((SparseArraySegment<int32>*)seg)->elements[i /*+ seg->length*/];
17501751
if (ival == JavascriptNativeIntArray::MissingItem)
17511752
{
1753+
AssertMsgAndFailFast(newSeg != intArray->head || !intArray->HasNoMissingValues(), "Unexpected missing item during array conversion");
17521754
continue;
17531755
}
17541756
newSeg->elements[i] = (double)ival;
@@ -2016,6 +2018,7 @@ using namespace Js;
20162018
ival = ((SparseArraySegment<int32>*)seg)->elements[i];
20172019
if (ival == JavascriptNativeIntArray::MissingItem)
20182020
{
2021+
AssertMsgAndFailFast(seg != intArray->head || !intArray->HasNoMissingValues(), "Unexpected missing item during array conversion");
20192022
continue;
20202023
}
20212024
newSeg->elements[i] = JavascriptNumber::ToVar(ival, scriptContext);
@@ -2050,6 +2053,7 @@ using namespace Js;
20502053
ival = ((SparseArraySegment<int32>*)seg)->elements[i];
20512054
if (ival == JavascriptNativeIntArray::MissingItem)
20522055
{
2056+
AssertMsgAndFailFast(seg != intArray->head || !intArray->HasNoMissingValues(), "Unexpected missing item during array conversion");
20532057
((SparseArraySegment<Var>*)seg)->elements[i] = (Var)JavascriptArray::MissingItem;
20542058
}
20552059
else
@@ -2229,6 +2233,7 @@ using namespace Js;
22292233
{
22302234
if (SparseArraySegment<double>::IsMissingItem(&((SparseArraySegment<double>*)seg)->elements[i]))
22312235
{
2236+
AssertMsgAndFailFast(seg != fArray->head || !fArray->HasNoMissingValues(), "Unexpected missing item during conversion");
22322237
if (seg == newSeg)
22332238
{
22342239
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)