Skip to content

Commit

Permalink
adding better size assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
tsatke committed Jun 27, 2024
1 parent bc77404 commit cb88531
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ext2/src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ impl DirEntry {
}

fn from(dir_entries_have_type: bool, value: &[u8]) -> Self {
let required_size = Self::size(0);
debug_assert!(
value.len() >= 8,
"need at least 8 byte, but got {}",
value.len() >= required_size as usize,
"need at least {required_size} byte, but got {}",
value.len()
);

Expand All @@ -194,6 +195,10 @@ impl DirEntry {
} else {
None
};

let required_size = Self::size(name_length); // now that we have the name length, we can compute the actual required size
debug_assert!(value.len() >= Self::size(name_length) as usize, "need at least {} byte, but have only {}", required_size, value.len());

let name_bytes = value[8..8 + name_length as usize].to_vec();
Self {
inode: InodeAddress::new(arr.inode).unwrap(),
Expand Down

0 comments on commit cb88531

Please sign in to comment.