Skip to content

Commit

Permalink
[1.3>1.4] [1.2>1.3] [MERGE #2196 @suwc] Change to address CVE-2016-7202
Browse files Browse the repository at this point in the history
Merge pull request #2196 from suwc:build/suwc/bugfix

Heap overflow in Array.prototype.reverse
In Array.prototype.reverse, array length is cached and used in ReverseHelper().
ReverseHelper() could invoke FillFromPrototypes(), which can cause a side-effect on the array,
including changing its length. Therefore, the use of cached array length to calculate segment left index could result in overflow. Fix by clamping array length at zero.
  • Loading branch information
Suwei Chen committed Dec 13, 2016
2 parents 2e4bd49 + 7fd0244 commit 091eeca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Runtime/Library/JavascriptArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5334,7 +5334,7 @@ namespace Js
((SparseArraySegment<Var>*)seg)->ReverseSegment(recycler);
}

seg->left = ((uint32)length) - (seg->left + seg->length);
seg->left = ((uint32)length) > (seg->left + seg->length) ? ((uint32)length) - (seg->left + seg->length) : 0;

seg->next = prevSeg;
// Make sure size doesn't overlap with next segment.
Expand Down
19 changes: 19 additions & 0 deletions test/Array/Array_TypeConfusion_bugs.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,5 +574,24 @@ var tests = [
assert.areEqual([0x41424344], Array.prototype.slice.call(y));
}
},
{
name: "[MSRC34994,35226] heap overflow in Array.prototype.reverse",
body: function ()
{
var count = 0;
arr = new Array(100);
var desc = Object.getOwnPropertyDescriptor(Array.prototype, 1);
Object.defineProperty(Array.prototype, 1, { get: function () {
count++;
if (count == 1) {
arr.push(null);
}
}});

arr.reverse();
restorePropertyFromDescriptor(Array.prototype, 1, desc);
assert.areEqual(101, arr.length);
}
},
];
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

0 comments on commit 091eeca

Please sign in to comment.