dermesser / leveldb-rs

A reimplementation of LevelDB in Rust (no bindings).
Other
515 stars 60 forks source link

Can't use `next()` when database contains the empty byte slice `&[]` as a key #16

Closed Sword-Smith closed 2 years ago

Sword-Smith commented 2 years ago

The function truncate_to_userkey panics if the empty byte vector is used as key. This can be fixed by changing the below > to a >=. The function truncate_to_userkey is called when you have a DBIterator where next() is called.

pub fn truncate_to_userkey(ikey: &mut Vec<u8>) {
    let len = ikey.len();
    assert!(len > 8);
    ikey.truncate(len - 8);
}

Suggested fix: Change src/key_types.rs line 212 to: assert!(len >= 8);