Skip to content

Commit 96c8b12

Browse files
committed
[MERGE #2201 @tcare] Array.prototype.unshift does not marshal parameters correctly
Merge pull request #2201 from tcare:unshift 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.
2 parents 341a8c9 + e193897 commit 96c8b12

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lib/Runtime/Library/JavascriptArray.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7563,7 +7563,7 @@ namespace Js
75637563
{
75647564
return res;
75657565
}
7566-
if (JavascriptArray::Is(args[0]))
7566+
if (JavascriptArray::Is(args[0]) && !JavascriptArray::FromVar(args[0])->IsCrossSiteObject())
75677567
{
75687568
#if ENABLE_COPYONACCESS_ARRAY
75697569
JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(args[0]);

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)