From df016f07a7a5b504d9b73f41743f0da0d295dd01 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Fri, 14 Jun 2013 15:36:01 +0100 Subject: [PATCH] [space map disk] Add a bounds check when accessing block data. This means we get a more helpful message in the exception. --- persistent-data/space-maps/disk.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/persistent-data/space-maps/disk.cc b/persistent-data/space-maps/disk.cc index 57b8baa..ae1a612 100644 --- a/persistent-data/space-maps/disk.cc +++ b/persistent-data/space-maps/disk.cc @@ -443,13 +443,26 @@ namespace { } private: + void check_block(block_address b) const { + if (b >= nr_blocks_) { + std::ostringstream out; + out << "space map disk: block out of bounds (" + << b << " >= " << nr_blocks_ << ")"; + throw std::runtime_error(out.str()); + } + } + ref_t lookup_bitmap(block_address b) const { + check_block(b); + index_entry ie = indexes_->find_ie(b / ENTRIES_PER_BLOCK); bitmap bm(tm_, ie, bitmap_validator_); return bm.lookup(b % ENTRIES_PER_BLOCK); } void insert_bitmap(block_address b, unsigned n) { + check_block(b); + if (n > 3) throw runtime_error("bitmap can only hold 2 bit values");