@@ -12,6 +12,7 @@ var runArrayTests = function (it) {
12
12
var ifSymbolUnscopablesIt = isSymbol ( Sym . unscopables ) ? it : it . skip ;
13
13
var ifShimIt = ( typeof process !== 'undefined' && process . env . NO_ES6_SHIM ) ? it . skip : it ;
14
14
var ifSupportsDescriptorsIt = Object . getOwnPropertyDescriptor ? it : it . skip ;
15
+ var ifHasDunderProtoIt = [ ] . __proto__ === Array . prototype ? it : it . skip ;
15
16
16
17
var isNegativeZero = function ( x ) {
17
18
return ( 1 / x ) < 0 ;
@@ -399,6 +400,66 @@ var runArrayTests = function (it) {
399
400
expect ( result ) . to . have . ownProperty ( '1' ) ;
400
401
expect ( result ) . to . eql ( { 0 : 'foo' , 1 : 'foo' , 2 : 1 , length : 3 } ) ;
401
402
} ) ;
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
+ } ) ;
402
463
} ) ;
403
464
404
465
describe ( '#find()' , function ( ) {
0 commit comments