Fix #1493 Path#add crashes whith 1000000 segments

This commit is contained in:
sasensi 2018-10-02 14:09:34 +02:00
parent 6cbf5292da
commit fc5bb4b10e
2 changed files with 14 additions and 2 deletions

View file

@ -404,8 +404,10 @@ var Path = PathItem.extend(/** @lends Path# */{
this._updateSelection(segment, 0, segment._selection);
}
if (append) {
// Append them all at the end by using push
segments.push.apply(segments, segs);
// Append them all at the end.
// Use a loop as it is the best way to handle big arrays (see #1493)
for (var i = 0; i < segs.length; i++)
segments.push(segs[i]);
} else {
// Insert somewhere else
segments.splice.apply(segments, [index, 0].concat(segs));

View file

@ -611,3 +611,13 @@ test('Path#arcTo(from, through, to); where from, through and to all share the sa
}
equals(error != null, true, 'We expect this arcTo() command to throw an error');
});
test('#1493 Path#add with 1000000 segments', function() {
var path = new Path();
for (var i=0; i<1000000; i++)
{
path.add(new Point(0,0));
}
path.clone();
expect(0);
});