From 030e3efbc41f1f4f8d3fd2c64da235869b0f6f0b Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 2 Oct 2017 18:04:37 +0100 Subject: [PATCH] lib/bloom: Add some missing preconditions on n_bytes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit These shouldn’t change the bloom filter’s behaviour at all, but make it a bit more obvious what the programmatical limitations are on the sizes it can deal with. In reality, those sizes should never be reached because they won’t fit in a DNS-SD record. Signed-off-by: Philip Withnall Closes: #1239 Approved by: cgwalters --- src/libostree/ostree-bloom.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libostree/ostree-bloom.c b/src/libostree/ostree-bloom.c index 9bd2ad28..c6de2640 100644 --- a/src/libostree/ostree-bloom.c +++ b/src/libostree/ostree-bloom.c @@ -76,7 +76,7 @@ struct _OstreeBloom { guint ref_count; - gsize n_bytes; + gsize n_bytes; /* 0 < n_bytes <= G_MAXSIZE / 8 */ gboolean is_mutable; /* determines which of [im]mutable_bytes is accessed */ union { @@ -117,6 +117,7 @@ ostree_bloom_new (gsize n_bytes, g_autoptr(OstreeBloom) bloom = NULL; g_return_val_if_fail (n_bytes > 0, NULL); + g_return_val_if_fail (n_bytes <= G_MAXSIZE / 8, NULL); g_return_val_if_fail (k > 0, NULL); g_return_val_if_fail (hash_func != NULL, NULL); @@ -159,6 +160,7 @@ ostree_bloom_new_from_bytes (GBytes *bytes, g_return_val_if_fail (bytes != NULL, NULL); g_return_val_if_fail (g_bytes_get_size (bytes) > 0, NULL); + g_return_val_if_fail (g_bytes_get_size (bytes) <= G_MAXSIZE / 8, NULL); g_return_val_if_fail (k > 0, NULL); g_return_val_if_fail (hash_func != NULL, NULL); -- 2.30.2