diff options
author | Vinnie Falco <vinnie.falco@gmail.com> | 2013-07-01 08:36:32 -0700 |
---|---|---|
committer | Vinnie Falco <vinnie.falco@gmail.com> | 2013-07-01 08:36:32 -0700 |
commit | fb1da62318f5a7f6e3ec31cdc02178a5445870e4 (patch) | |
tree | 4ef6f0b1017c747e84132427666eea4a36d10b0d /src/leveldb/table/block.cc | |
parent | 28bcf3b7ef804f7084938b21708b29c1f5d7c8f8 (diff) | |
parent | adae78ea9940f4d44382967d1296e7db0b54a4de (diff) |
Merge commit 'adae78ea9940f4d44382967d1296e7db0b54a4de' into leveldb-squashed
Diffstat (limited to 'src/leveldb/table/block.cc')
-rw-r--r-- | src/leveldb/table/block.cc | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/leveldb/table/block.cc b/src/leveldb/table/block.cc index ab83c1112c..79ea9d9ee5 100644 --- a/src/leveldb/table/block.cc +++ b/src/leveldb/table/block.cc @@ -16,7 +16,7 @@ namespace leveldb { inline uint32_t Block::NumRestarts() const { - assert(size_ >= 2*sizeof(uint32_t)); + assert(size_ >= sizeof(uint32_t)); return DecodeFixed32(data_ + size_ - sizeof(uint32_t)); } @@ -27,11 +27,12 @@ Block::Block(const BlockContents& contents) if (size_ < sizeof(uint32_t)) { size_ = 0; // Error marker } else { - restart_offset_ = size_ - (1 + NumRestarts()) * sizeof(uint32_t); - if (restart_offset_ > size_ - sizeof(uint32_t)) { - // The size is too small for NumRestarts() and therefore - // restart_offset_ wrapped around. + size_t max_restarts_allowed = (size_-sizeof(uint32_t)) / sizeof(uint32_t); + if (NumRestarts() > max_restarts_allowed) { + // The size is too small for NumRestarts() size_ = 0; + } else { + restart_offset_ = size_ - (1 + NumRestarts()) * sizeof(uint32_t); } } } @@ -253,7 +254,7 @@ class Block::Iter : public Iterator { }; Iterator* Block::NewIterator(const Comparator* cmp) { - if (size_ < 2*sizeof(uint32_t)) { + if (size_ < sizeof(uint32_t)) { return NewErrorIterator(Status::Corruption("bad block contents")); } const uint32_t num_restarts = NumRestarts(); |