Skip to content

Commit 2e49fe9

Browse files
author
David Figatner
authored
Prevent nextPos for connectEdges from accessing past end of array (w/additional checks) (#147)
* rebuilt with out-of-index PR * added dist * added another out of bounds check * added another bounds check * version change * added another check * updated version * updated version * updated with error catching * added back dist for merging * added space in .gitignore * replaced version number * removed dist files * removed yarn.lock * cleaning up package.json
1 parent a1bb07e commit 2e49fe9

File tree

4 files changed

+7624
-1884
lines changed

4 files changed

+7624
-1884
lines changed

demo/js/bundle.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function (L$1) {
22
'use strict';
33

4-
L$1 = L$1 && L$1.hasOwnProperty('default') ? L$1['default'] : L$1;
4+
L$1 = L$1 && Object.prototype.hasOwnProperty.call(L$1, 'default') ? L$1['default'] : L$1;
55

66
L$1.Coordinates = L$1.Control.extend({
77
options: {
@@ -1663,7 +1663,7 @@
16631663
if (next) {
16641664
if (possibleIntersection(event, next.key, eventQueue) === 2) {
16651665
computeFields(event, prevEvent, operation);
1666-
computeFields(event, next.key, operation);
1666+
computeFields(next.key, event, operation);
16671667
}
16681668
}
16691669

@@ -1768,8 +1768,8 @@
17681768
*/
17691769
function nextPos(pos, resultEvents, processed, origPos) {
17701770
var newPos = pos + 1,
1771-
p = resultEvents[pos].point,
1772-
p1;
1771+
p = resultEvents[pos].point,
1772+
p1;
17731773
var length = resultEvents.length;
17741774

17751775
if (newPos < length)
@@ -1778,10 +1778,12 @@
17781778
while (newPos < length && p1[0] === p[0] && p1[1] === p[1]) {
17791779
if (!processed[newPos]) {
17801780
return newPos;
1781-
} else {
1781+
} else {
17821782
newPos++;
17831783
}
1784-
p1 = resultEvents[newPos].point;
1784+
if (newPos < length) {
1785+
p1 = resultEvents[newPos].point;
1786+
}
17851787
}
17861788

17871789
newPos = pos - 1;
@@ -1859,7 +1861,9 @@
18591861
// Helper function that combines marking an event as processed with assigning its output contour ID
18601862
var markAsProcessed = function (pos) {
18611863
processed[pos] = true;
1862-
resultEvents[pos].outputContourId = contourId;
1864+
if (pos < resultEvents.length && resultEvents[pos]) {
1865+
resultEvents[pos].outputContourId = contourId;
1866+
}
18631867
};
18641868

18651869
var pos = i;
@@ -1879,7 +1883,7 @@
18791883

18801884
pos = nextPos(pos, resultEvents, processed, origPos);
18811885

1882-
if (pos == origPos) {
1886+
if (pos == origPos || pos >= resultEvents.length || !resultEvents[pos]) {
18831887
break;
18841888
}
18851889
}

0 commit comments

Comments
 (0)