Two more checks

This commit is contained in:
Marcus Holland-Moritz 2021-03-30 18:17:07 +02:00
parent 72f56004ec
commit 69fc251cd6
2 changed files with 7 additions and 0 deletions

View File

@ -265,6 +265,9 @@ class block_cache_ final : public block_cache::impl {
void set_block_size(size_t size) override {
// XXX: This currently inevitably clears the cache
if (size == 0) {
DWARFS_THROW(runtime_error, "block size is zero");
}
auto max_blocks = std::max<size_t>(options_.max_bytes / size, 1);
if (!block_.empty() && max_blocks > block_.size()) {

View File

@ -225,6 +225,10 @@ void check_packed_tables(global_metadata::Meta const* meta) {
void check_chunks(global_metadata::Meta const* meta) {
auto block_size = meta->block_size();
if (block_size == 0 || (block_size & (block_size - 1))) {
DWARFS_THROW(runtime_error, "invalid block size");
}
for (auto c : meta->chunks()) {
if (c.offset() >= block_size || c.size() > block_size) {
DWARFS_THROW(runtime_error, "chunk offset/size out of range");