Skip to content

Commit

Permalink
Don't panic on bad size header
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Oct 5, 2022
1 parent 43b451e commit 3ecd8e8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,14 @@ impl ValueTable {
},
}
}

if buf.offset() > entry_end {
return Err(crate::error::Error::Corruption(format!(
"Unexpected entry size. Expected at least {} bytes",
entry_end
)))
}

if !f(buf.remaining_to(entry_end)) {
break
};
Expand Down Expand Up @@ -1429,4 +1437,27 @@ mod test {
});
assert_eq!(table.get(key, 1, log.overlays()).unwrap(), Some((val, compressed)));
}

#[test]
fn bad_size_header() {
let dir = tempdir().unwrap();
let table = new_table(&dir, Some(36), &rc_options());
let log = new_log(&dir);

let key = &TableKey::Partial(key(1));
let val = value(4);

let compressed = false;
write_ops(&table, &log, |writer| {
table.write_insert_plan(key, &val, writer, compressed).unwrap();
});
// Corrupt entry 1
let zeroes = [0u8, 0u8];
table.file.write_at(&zeroes, table.entry_size as u64).unwrap();
let log = new_log(&dir);
assert!(matches!(
table.get(key, 1, log.overlays()),
Err(crate::error::Error::Corruption(_))
));
}
}

0 comments on commit 3ecd8e8

Please sign in to comment.