Closed pecollet closed 3 years ago
in ErdosRenyiRelationshipGenerator :
protected List<Pair<Integer, Integer>> doGenerateEdges() {
long threshold = getConfiguration().getNumberOfEdges() * 4;
long potentialEdges = getConfiguration().getNumberOfNodes() * (getConfiguration().getNumberOfNodes() - 1);
if (threshold > potentialEdges) {
return doGenerateEdgesWithOmitList(); // Make sure to avoid edges
}
The integer multiplication of numberOfNodes can silently overflow and produce negative values, causing the code to branch into doGenerateEdgesWithOmitList()
and then access negative list indexes.
=> convert to long before multiplying
The bug actually affects calls to the procedure with numberOfNodes such that numberOfNodes * (numberOfNodes-1)
overflows as a negative int (and when it overflows positive it may also do unexpected things). So nothing to do with 500000 as my tests made me believe. It can happen for any value over 46341 which is the limit at which the integer multiplication starts overflowing.
Expected Behavior (Mandatory)
apoc.generate.er goes through and generates the graph
Actual Behavior (Mandatory)
apoc.generate.er
: Caused by: java.lang.IndexOutOfBoundsException: Index -559948134 out of bounds for length 510000"How to Reproduce the Problem
Steps (Mandatory)
Screenshots (where it's possibile)
Specifications (Mandatory)
Versions