Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge r229850 - Race Condition in arrayProtoFuncReverse() causes wron…
…g results or crash https://bugs.webkit.org/show_bug.cgi?id=183901 Reviewed by Keith Miller. JSTests: New test. * stress/array-reverse-doesnt-clobber.js: Added. (testArrayReverse): (createArrayOfArrays): (createArrayStorage): Source/JavaScriptCore: Added write barriers to ensure the reversed contents are properly marked. * runtime/ArrayPrototype.cpp: (JSC::arrayProtoFuncReverse):
- Loading branch information
1 parent
3356496
commit 776c272
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// This tests that array.Prototype.reverse() doesn't inadvertently clobber indexed properties. | ||
// This test shouldn't throw or crash. | ||
|
||
const outerArrayLength = 10000; | ||
const innerArrayLength = 128; | ||
|
||
function testArrayReverse(createArray) | ||
{ | ||
const limit = 5; | ||
let save = [0, 0]; | ||
|
||
for (let at = 0; at < limit; at++) { | ||
let arr = createArray(); | ||
|
||
let v = []; | ||
for (let i = 0; i < 273; i++) { | ||
for (let j = 0; j < 8; j++) | ||
arr.reverse(); | ||
|
||
v.push(new String("X").repeat(123008)); | ||
} | ||
|
||
for (let i = 0; i < arr.length; i++) { | ||
if (arr[i].length != innerArrayLength) | ||
throw "arr[" + i + "].length has changed from " + innerArrayLength + " to " + arr[i].length; | ||
} | ||
|
||
let f = []; | ||
for (let i = 0; i < 1000; i++) | ||
f.push(new Array(16).fill(0x42424242)); | ||
|
||
save.push(arr); | ||
save.push(v); | ||
save.push(f); | ||
} | ||
} | ||
|
||
function createArrayOfArrays() | ||
{ | ||
let result = new Array(outerArrayLength); | ||
|
||
for (let i = 0; i < result.length; i++) | ||
result[i] = new Array(innerArrayLength).fill(0x41414141); | ||
|
||
return result; | ||
} | ||
|
||
var alt = 0; | ||
|
||
function createArrayStorage() | ||
{ | ||
let result = createArrayOfArrays(); | ||
|
||
if (!(typeof ensureArrayStorage === undefined) && alt++ % 0) | ||
ensureArrayStorage(result); | ||
|
||
return result; | ||
} | ||
|
||
testArrayReverse(createArrayOfArrays); | ||
testArrayReverse(createArrayStorage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters