Skip to content

Commit f029c06

Browse files
committed
Array.prototype.unshift does not marshal parameters correctly
Fixes OS 9357224. Array.prototype.unshift prepends array values to 'this' array by calling JavascriptArray::FillFromArgs. FillFromArgs makes the assumption that values are already marshalled to the same context as 'this'. It is possible to have a situation in Array.prototype.unshift where the source array is in another context than the parameters passed in, triggering the assert. Other users of FillFromArgs (e.g. new Array()) don't seem to be able to hit this situation. Fix is to marshal values as we iterate in FillFromArgs.
1 parent bc31a6e commit f029c06

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

lib/Runtime/Library/JavascriptArray.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,7 @@ namespace Js
15441544
for (i = start; i < length; i++)
15451545
{
15461546
Var item = args[i + 1];
1547+
item = CrossSite::MarshalVar(GetScriptContext(), item);
15471548
this->DirectSetItemAt(i, item);
15481549
}
15491550

test/Array/shift_unshift.baseline

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ e instanceOf TypeError = true
4848
a.length = 1
4949
ary.length = 18
5050
arr.length = 6
51+
Crosssite new length: 2
5152
Overridden unshift
5253
Overridden unshift
5354
Overridden unshift

test/Array/shift_unshift.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ function test1(arr)
140140

141141
WScript.Echo("arr.length = " + test1(new Array(10)));
142142

143+
// OS 9357224: Array.prototype.unshift does not marshal parameters correctly
144+
function crossSiteUnshift() {
145+
var sc0 = WScript.LoadScript('', 'samethread');
146+
sc0.ary = [1];
147+
return sc0.eval('Array.prototype.unshift.call(ary, null)');
148+
}
149+
WScript.Echo("Crosssite new length: " + crossSiteUnshift()); // 2
150+
143151
//
144152
// To check bailouts for inlined unshift
145153
//
@@ -164,4 +172,3 @@ function foo()
164172
Array.prototype.unshift = function(){WScript.Echo ("Overridden unshift")};
165173
foo();
166174
WScript.Echo (a);
167-

0 commit comments

Comments
 (0)