Skip to content

Commit d760bc7

Browse files
author
Kenji Kikushima
committed
Add numEdges upperbound validation for R-MAT graph generator to prevent infinite loop.
1 parent c082385 commit d760bc7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

graphx/src/main/scala/org/apache/spark/graphx/util/GraphGenerators.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ object GraphGenerators {
133133
// This ensures that the 4 quadrants are the same size at all recursion levels
134134
val numVertices = math.round(
135135
math.pow(2.0, math.ceil(math.log(requestedNumVertices) / math.log(2.0)))).toInt
136+
val numEdgesUpperBound =
137+
math.pow(2.0, 2 * ((math.log(numVertices) / math.log(2.0)) - 1)).toInt
138+
if (numEdgesUpperBound < numEdges) {
139+
throw new IllegalArgumentException("R-MAT accepts " + numEdgesUpperBound
140+
+ " or less numEdges when numVertices is " + numVertices)
141+
}
136142
var edges: Set[Edge[Int]] = Set()
137143
while (edges.size < numEdges) {
138144
if (edges.size % 100 == 0) {

0 commit comments

Comments
 (0)