From 6e8ae4a7146dc7c3582527e66e07def10d6bfd88 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Mon, 27 Dec 2021 18:08:20 +0100 Subject: [PATCH] Do not exceed maximum call stack when parsing TopoJSON --- src/ol/format/TopoJSON.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ol/format/TopoJSON.js b/src/ol/format/TopoJSON.js index f6e1e0c5a5..0253ce5ece 100644 --- a/src/ol/format/TopoJSON.js +++ b/src/ol/format/TopoJSON.js @@ -186,7 +186,7 @@ const GEOMETRY_READERS = { function concatenateArcs(indices, arcs) { /** @type {Array} */ const coordinates = []; - let index, arc; + let index; for (let i = 0, ii = indices.length; i < ii; ++i) { index = indices[i]; if (i > 0) { @@ -195,16 +195,17 @@ function concatenateArcs(indices, arcs) { } if (index >= 0) { // forward arc - arc = arcs[index]; + const arc = arcs[index]; + for (let j = 0, jj = arc.length; j < jj; ++j) { + coordinates.push(arc[j].slice(0)); + } } else { // reverse arc - arc = arcs[~index].slice().reverse(); + const arc = arcs[~index]; + for (let j = arc.length - 1; j >= 0; --j) { + coordinates.push(arc[j].slice(0)); + } } - coordinates.push.apply(coordinates, arc); - } - // provide fresh copies of coordinate arrays - for (let j = 0, jj = coordinates.length; j < jj; ++j) { - coordinates[j] = coordinates[j].slice(); } return coordinates; }