From 40ff06f11f03086a20e88bcb69ccddbad83af828 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 11 Jan 2017 15:38:24 -0800 Subject: [PATCH] bloom: ensure min values. --- lib/utils/bloom.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/utils/bloom.js b/lib/utils/bloom.js index a8f696c2..2fe23837 100644 --- a/lib/utils/bloom.js +++ b/lib/utils/bloom.js @@ -272,6 +272,7 @@ Bloom.fromRate = function fromRate(items, rate, update) { assert(rate >= 0 && rate <= 1, '`rate` must be between 0.0 and 1.0.'); size = (-1 / LN2SQUARED * items * Math.log(rate)) | 0; + size = Math.max(8, size); if (update !== -1) size = Math.min(size, Bloom.MAX_BLOOM_FILTER_SIZE * 8); @@ -433,6 +434,7 @@ RollingFilter.prototype.fromRate = function fromRate(items, rate) { items = ((size + 63) / 64 | 0) << 1; items >>>= 0; + items = Math.max(1, items); tweak = (Math.random() * 0x100000000) >>> 0;