From 8852f5f8ff3d521897175ddeb711d6b77e03fa8a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 6 Dec 2011 14:13:38 +0000 Subject: [PATCH] Fixing #1976 by allowing allocations between INT_MAX and SIZE_MAX and at the same time limiting BF size for datastore to 2 GB. Also fixing infinite loop when creating BFs of sizes between 2-4 GB --- src/datastore/gnunet-service-datastore.c | 5 ++++- src/util/common_allocation.c | 1 - src/util/container_bloomfilter.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index be88d288e..327244ffd 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c @@ -1492,7 +1492,10 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, cache_size = quota / 8; /* Or should we make this an option? */ GNUNET_STATISTICS_set (stats, gettext_noop ("# cache size"), cache_size, GNUNET_NO); - bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */ + if (quota / 32LL > (1 << 31)) + bf_size = (1 << 31); /* absolute limit: ~2 GB, beyond that BF just won't help anyway */ + else + bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */ fn = NULL; if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "DATASTORE", "BLOOMFILTER", diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index fd5e993e2..5e1f75eb7 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c @@ -136,7 +136,6 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber) return NULL; #endif - GNUNET_assert_at (size < INT_MAX, filename, linenumber); result = malloc (size); if (result == NULL) return NULL; diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index 180aab4c3..31e777dc3 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c @@ -463,7 +463,8 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, if (size < BUFFSIZE) size = BUFFSIZE; ui = 1; - while (ui < size) + while ( (ui < size) && + (ui * 2 > ui) ) ui *= 2; size = ui; /* make sure it's a power of 2 */ -- 2.25.1