Skip to content

Commit

Permalink
lib/bloom: Fix bloom hashing on 32-bit architectures
Browse files Browse the repository at this point in the history
There was an implicit cast from guint64 to gsize (which is 32-bit on
armhf, for example) before the modulus arithmetic which safely narrows
the index.

Fix that by using a guint64 intermediate variable and making the cast
explicit.

Signed-off-by: Philip Withnall <[email protected]>

Closes: #1231
Approved by: cgwalters
  • Loading branch information
pwithnall authored and rh-atomic-bot committed Oct 1, 2017
1 parent 4262a4b commit 1673601
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/libostree/ostree-bloom.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ ostree_bloom_maybe_contains (OstreeBloom *bloom,

for (i = 0; i < bloom->k; i++)
{
gsize idx;
guint64 idx;

idx = bloom->hash_func (element, i);

if (!ostree_bloom_get_bit (bloom, idx % (bloom->n_bytes * 8)))
if (!ostree_bloom_get_bit (bloom, (gsize) (idx % (bloom->n_bytes * 8))))
return FALSE; /* definitely not in the set */
}

Expand Down Expand Up @@ -337,8 +337,8 @@ ostree_bloom_add_element (OstreeBloom *bloom,

for (i = 0; i < bloom->k; i++)
{
gsize idx = bloom->hash_func (element, i);
ostree_bloom_set_bit (bloom, idx % (bloom->n_bytes * 8));
guint64 idx = bloom->hash_func (element, i);
ostree_bloom_set_bit (bloom, (gsize) (idx % (bloom->n_bytes * 8)));
}
}

Expand Down

0 comments on commit 1673601

Please sign in to comment.