Skip to content

Commit f975808

Browse files
committed
Add some bounds check on capacityfactor
1 parent e95f1dc commit f975808

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Src/FastData/Internal/Misc/HashData.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ internal record HashData(ulong[] HashCodes, int CapacityFactor, bool HashCodesUn
77
{
88
internal static HashData Create<T>(T[] data, int capacityFactor, HashFunc<T> func)
99
{
10-
ulong size = (ulong)(data.Length * capacityFactor);
10+
if (capacityFactor <= 0)
11+
throw new InvalidOperationException("HashCapacityFactor must be greater than 0.");
12+
13+
ulong size = checked((ulong)data.Length * (ulong)capacityFactor);
14+
15+
if (size == 0)
16+
throw new InvalidOperationException("HashCapacityFactor results in zero-sized hash table.");
1117

1218
ulong[] hashCodes = new ulong[size];
1319
HashSet<ulong> uniqSet = new HashSet<ulong>();

0 commit comments

Comments
 (0)