changeset 229:21615fb1c05b

table_cache: Assert that table files are not empty.
author Lewin Bormann <lbo@spheniscida.de>
date Sun, 10 Sep 2017 14:04:58 +0200
parents 219a3a620276
children 188a52d70d4e
files src/table_cache.rs
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/table_cache.rs	Sun Sep 10 14:04:31 2017 +0200
+++ b/src/table_cache.rs	Sun Sep 10 14:04:58 2017 +0200
@@ -3,7 +3,7 @@
 //! returned.
 
 use cache::{self, Cache};
-use error::Result;
+use error::{err, StatusCode, Result};
 use key_types::InternalKey;
 use options::Options;
 use table_reader::Table;
@@ -64,8 +64,11 @@
     fn open_table(&mut self, file_num: FileNum) -> Result<Table> {
         let name = table_name(&self.dbname, file_num, DEFAULT_SUFFIX);
         let path = Path::new(&name);
+        let file_size = self.opts.env.size_of(&path)?;
+        if file_size == 0 {
+            return err(StatusCode::InvalidData, "file is empty");
+        }
         let file = Rc::new(self.opts.env.open_random_access_file(&path)?);
-        let file_size = self.opts.env.size_of(&path)?;
         // No SSTable file name compatibility.
         let table = Table::new(self.opts.clone(), file, file_size)?;
         self.cache.insert(&filenum_to_key(file_num), table.clone());