From fc5bb4b10e7cbcde926cde272b6533e0747391fc Mon Sep 17 00:00:00 2001 From: sasensi Date: Tue, 2 Oct 2018 14:09:34 +0200 Subject: [PATCH] Fix #1493 Path#add crashes whith 1000000 segments --- src/path/Path.js | 6 ++++-- test/tests/Path.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/path/Path.js b/src/path/Path.js index 42eaa34e..81bcfa05 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -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)); diff --git a/test/tests/Path.js b/test/tests/Path.js index 91a1eacf..70cd401e 100644 --- a/test/tests/Path.js +++ b/test/tests/Path.js @@ -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); +});