Skip to content

Commit

Permalink
Add padding buckets to avoid buffer overrun on SingleTable
Browse files Browse the repository at this point in the history
  • Loading branch information
oNaiPs authored and jbapple-cloudera committed Jun 15, 2018
1 parent 1869140 commit 0af0aab
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/singletable.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class SingleTable {
static const size_t kBytesPerBucket =
(bits_per_tag * kTagsPerBucket + 7) >> 3;
static const uint32_t kTagMask = (1ULL << bits_per_tag) - 1;
// NOTE: accomodate extra buckets if necessary to avoid overrun
// as we always read a uint64
static const size_t kPaddingBuckets =
((((kBytesPerBucket + 7) / 8) * 8) - 1) / kBytesPerBucket;

struct Bucket {
char bits_[kBytesPerBucket];
Expand All @@ -29,8 +33,8 @@ class SingleTable {

public:
explicit SingleTable(const size_t num) : num_buckets_(num) {
buckets_ = new Bucket[num_buckets_];
memset(buckets_, 0, kBytesPerBucket * num_buckets_);
buckets_ = new Bucket[num_buckets_ + kPaddingBuckets];
memset(buckets_, 0, kBytesPerBucket * (num_buckets_ + kPaddingBuckets));
}

~SingleTable() {
Expand Down

0 comments on commit 0af0aab

Please sign in to comment.