Skip to content

Commit a246ed0

Browse files
committed
Check against index too large in SparseIntArray
1 parent 3585609 commit a246ed0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

compiler/src/dotty/tools/dotc/util/SparseIntArray.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ class SparseIntArray:
2828

2929
def update(index: Int, value: Value): Unit =
3030
require(index >= 0)
31-
while capacity <= index do grow()
31+
while capacity <= index do
32+
require(root.level < MaxLevels, "array index too large, maximum is 2^30 - 1")
33+
grow()
3234
if !root.update(index, value) then siz += 1
3335

3436
/** Remove element at `index` if it is present
@@ -76,6 +78,7 @@ object SparseIntArray:
7678

7779
private inline val NodeSizeLog = 5
7880
private inline val NodeSize = 1 << NodeSizeLog
81+
private inline val MaxLevels = 5 // max size is 2 ^ ((MaxLevels + 1) * NodeSizeLog) = 2 ^ 30
7982

8083
/** The exposed representation. Should be used just for nodeCount and
8184
* low-level toString.

0 commit comments

Comments
 (0)