Closed
Description
Explanation
The getDistinctIndicesBis
function within getDistinctIndices
will fail with a Maximum call stack size exceeded error when there are too few distinct indizes being returned while n < size.
How to reproduce
const filter = new BloomFilter(39, 28);
filter.add("da5e21f8a67c4163f1a53ef43515bd027967da305ecfc741b2c3f40f832b7f82");
This code will trigger the issue.
Why does this happen?
// This returns the same hashes after n is larger than size
const hashes = hashTwice(elem, true, seed! + (size % n));
// This return from the doubleHashing function will also return the same values when called with the same hashes and different n values
return Math.abs((hashA + n * hashB) % size);
This combined with the filtering of double indizes in getDistinctIndicesBis
will lead to the issue.
Its important to note that this will only happen in certain cases with high hash count and a low bit count.