Skip to content

Commit 14866a7

Browse files
committed
[Tests] add failing tests from tc39/test262#2443
1 parent 52925ba commit 14866a7

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

test/array.js

+61
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var runArrayTests = function (it) {
1212
var ifSymbolUnscopablesIt = isSymbol(Sym.unscopables) ? it : it.skip;
1313
var ifShimIt = (typeof process !== 'undefined' && process.env.NO_ES6_SHIM) ? it.skip : it;
1414
var ifSupportsDescriptorsIt = Object.getOwnPropertyDescriptor ? it : it.skip;
15+
var ifHasDunderProtoIt = [].__proto__ === Array.prototype ? it : it.skip;
1516

1617
var isNegativeZero = function (x) {
1718
return (1 / x) < 0;
@@ -399,6 +400,66 @@ var runArrayTests = function (it) {
399400
expect(result).to.have.ownProperty('1');
400401
expect(result).to.eql({ 0: 'foo', 1: 'foo', 2: 1, length: 3 });
401402
});
403+
404+
// https://github.com/tc39/test262/pull/2443
405+
describe('security issues', function () {
406+
// make a long integer Array
407+
function longDenseArray() {
408+
var a = [0];
409+
for (var i = 0; i < 1024; i++) {
410+
a[i] = i;
411+
}
412+
return a;
413+
}
414+
415+
describe('coerced-values-start-change-start', function () {
416+
var currArray;
417+
function shorten() {
418+
currArray.length = 20;
419+
return 1000;
420+
}
421+
422+
it('coercion side-effect makes start out of bounds', function () {
423+
currArray = longDenseArray();
424+
var array = [];
425+
array.length = 20;
426+
427+
expect(currArray.copyWithin(0, {valueOf: shorten})).to.deep.equal(array);
428+
});
429+
430+
ifHasDunderProtoIt('coercion side-effect makes start out of bounds with prototype', function () {
431+
currArray = longDenseArray();
432+
Object.setPrototypeOf(currArray, longDenseArray());
433+
434+
var array2 = longDenseArray();
435+
array2.length = 20;
436+
for (var i = 0; i < 24; i++) {
437+
array2[i] = Object.getPrototypeOf(currArray)[i + 1000];
438+
}
439+
440+
expect(currArray.copyWithin(0, {valueOf: shorten})).to.deep.equal(array2);
441+
});
442+
});
443+
444+
describe('coerced-values-start-change-target', function () {
445+
it('coercion side-effect makes target out of bounds', function () {
446+
function shorten() {
447+
currArray.length = 20;
448+
return 1;
449+
}
450+
451+
var array = longDenseArray();
452+
array.length = 20;
453+
for (var i = 0; i < 19; i++) {
454+
array[i + 1000] = array[i + 1];
455+
}
456+
457+
var currArray = longDenseArray();
458+
459+
expect(currArray.copyWithin(1000, {valueOf: shorten})).to.deep.equal(array);
460+
});
461+
});
462+
});
402463
});
403464

404465
describe('#find()', function () {

0 commit comments

Comments
 (0)