-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Hash
@indices
can grow larger than Int32::MAX bytes (#15347)
`Hash` can theoretically hold up to `Int32::MAX` entries, but `@indices` grows faster. Using `Int32` maths to calculate the memory size for `@indices` limits capacity to `Int32::MAX // 4`. This patch uses `Int64` maths instead to enable bigger hash sizes. Co-authored-by: Johannes Müller <[email protected]>
- Loading branch information
1 parent
2b544f1
commit c4682db
Showing
2 changed files
with
12 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "spec" | ||
|
||
it "creates Hash at maximum capacity" do | ||
# we don't try to go as high as Int32::MAX because it would allocate 18GB of | ||
# memory in total. This already tests for Int32 overflows while 'only' needing | ||
# 4.5GB of memory. | ||
Hash(Int32, Int32).new(initial_capacity: (Int32::MAX // 4) + 1) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters